Skip to content

Commit 2b17e09

Browse files
committed
Rename interface methods
1 parent 44d4fc8 commit 2b17e09

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

lib/view_component/base.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -618,21 +618,21 @@ def strip_trailing_whitespace(value = true)
618618
619619
```rb
620620
class #{self.class.name} < ViewComponent::Base
621-
configure do |config|
621+
configure_view_component do |config|
622622
config.strip_trailing_whitespace = #{value}
623623
end
624624
end
625625
```
626626
)
627627
)
628-
configuration.strip_trailing_whitespace = value
628+
view_component_config.strip_trailing_whitespace = value
629629
end
630630

631631
# Whether trailing whitespace will be stripped before compilation.
632632
#
633633
# @return [Boolean]
634634
def strip_trailing_whitespace?
635-
configuration.strip_trailing_whitespace
635+
view_component_config.strip_trailing_whitespace
636636
end
637637

638638
# Ensure the component initializer accepts the

lib/view_component/component_local_config.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,32 @@ def inheritable_copy
2828

2929
included do
3030
# :nocov:
31-
def configuration
32-
@_configuration ||= self.class.configuration.inheritable_copy
31+
def view_component_config
32+
@__vc_config ||= self.class.view_component_config.inheritable_copy
3333
end
3434

3535
private
3636

3737
def inherited(child)
38-
child.instance_variable_set(:@_configuration, nil)
38+
child.instance_variable_set(:@__vc_config, nil)
3939
super
4040
end
4141
# :nocov:
4242
end
4343

4444
class_methods do
45-
def configuration
46-
@_configuration ||= if respond_to?(:superclass) && superclass.respond_to?(:configuration)
47-
superclass.configuration.inheritable_copy
45+
def view_component_config
46+
@__vc_config ||= if respond_to?(:superclass) && superclass.respond_to?(:view_component_config)
47+
superclass.view_component_config.inheritable_copy
4848
else
4949
# create a new "anonymous" class that will host the compiled reader methods
5050
ViewComponent::ComponentLocalConfig::Configuration.new
5151
end
5252
end
5353

54-
def configure(&block)
55-
configuration.instance_eval(&block)
56-
configuration.compile_methods!
54+
def configure_component(&block)
55+
view_component_config.instance_eval(&block)
56+
view_component_config.compile_methods!
5757
end
5858
end
5959
end
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class ConfigurableComponent < ViewComponent::Base
4-
configure do |config|
4+
configure_component do |config|
55
config.strip_trailing_whitespace = true
66
end
77
end

test/sandbox/test/base_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ def test_uses_module_configuration
199199
end
200200

201201
def test_component_local_config_is_inheritable
202-
assert_equal false, ViewComponent::Base.configuration.strip_trailing_whitespace
202+
assert_equal false, ViewComponent::Base.view_component_config.strip_trailing_whitespace
203203
# This component doesn't call configure, so it should inherit the defaults.
204-
assert_equal false, AnotherComponent.configuration.strip_trailing_whitespace
204+
assert_equal false, AnotherComponent.view_component_config.strip_trailing_whitespace
205205
# This component overrides the defaults.
206-
assert_equal true, ConfigurableComponent.configuration.strip_trailing_whitespace
206+
assert_equal true, ConfigurableComponent.view_component_config.strip_trailing_whitespace
207207
end
208208
end

0 commit comments

Comments
 (0)