44
55module ViewComponent
66 class Config
7+ class Layer < ActiveSupport ::OrderedOptions ; end
78 class << self
89 # `new` without any arguments initializes the default configuration, but
910 # it's important to differentiate in case that's no longer the case in
1011 # future.
11- alias_method :default , :new
12-
13- def defaults
14- ActiveSupport ::OrderedOptions . new . merge! ( {
15- generate : default_generate_options ,
12+ def default
13+ Layer [
14+ generate : Layer [ preview_path : "" ] ,
1615 preview_controller : "ViewComponentsController" ,
1716 preview_route : "/rails/view_components" ,
1817 show_previews_source : false ,
@@ -26,7 +25,15 @@ def defaults
2625 test_controller : "ApplicationController" ,
2726 default_preview_layout : nil ,
2827 capture_compatibility_patch_enabled : false
29- } )
28+ ]
29+ end
30+
31+ def defaults
32+ default
33+ end
34+
35+ def blank
36+ Layer [ default . deep_transform_values { nil } ]
3037 end
3138
3239 # @!attribute generate
@@ -182,14 +189,14 @@ def default_generate_options
182189
183190 # @!attribute current
184191 # @return [ViewComponent::Config]
185- # Returns the current ViewComponent::Config. This is persisted against this
192+ # Returns the global ViewComponent::Config. This is persisted against this
186193 # class so that config options remain accessible before the rest of
187194 # ViewComponent has loaded. Defaults to an instance of ViewComponent::Config
188195 # with all other documented defaults set.
189- class_attribute :current , default : defaults , instance_predicate : false
196+ class_attribute :global , default : defaults , instance_predicate : false
190197
191198 def initialize
192- @config = self . class . defaults
199+ @config = self . class . blank
193200 end
194201
195202 delegate_missing_to :config
0 commit comments