File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33module ViewComponent
44 module ComponentLocalConfig
55 class Configuration
6- def initialize
7- @config = ActiveSupport ::OrderedOptions [
6+ def self . defaults
7+ ActiveSupport ::Configurable :: Configuration [
88 strip_trailing_whitespace : false
99 ]
1010 end
1111
12+ def initialize ( config = defaults )
13+ @config = config
14+ end
15+
1216 delegate_missing_to :@config
1317
1418 def inheritable_copy
15- new . instance_variable_set ( :@config , @config . inheritable_copy )
19+ self . class . new ( @config . inheritable_copy )
1620 end
21+
22+ private
23+
24+ delegate :defaults , to : :class
1725 end
1826
1927 extend ActiveSupport ::Concern
@@ -37,7 +45,7 @@ def configuration
3745 superclass . configuration . inheritable_copy
3846 else
3947 # create a new "anonymous" class that will host the compiled reader methods
40- Class . new ( ActiveSupport :: Configurable ::Configuration ) . new
48+ ViewComponent :: ComponentLocalConfig ::Configuration . new
4149 end
4250 end
4351
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ class ConfigurableComponent < ViewComponent ::Base
4+ configure do |config |
5+ config . strip_trailing_whitespace = true
6+ end
7+ end
Original file line number Diff line number Diff line change @@ -146,4 +146,9 @@ def test_no_method_error_does_not_reference_missing_helper
146146 MESSAGE
147147 assert !exception_message_regex . match? ( exception . message )
148148 end
149+
150+ def test_component_local_config_is_inheritable
151+ assert_equal false , ViewComponent ::Base . configuration . strip_trailing_whitespace
152+ assert_equal true , ConfigurableComponent . configuration . strip_trailing_whitespace
153+ end
149154end
You can’t perform that action at this time.
0 commit comments