1- require 'active_support/configurable '
1+ require 'active_support/ordered_options '
22require 'html_attributes_utils'
33
44[ %w( presenters *.rb ) , %w( refinements *.rb ) , %w( traits *.rb ) , %w( *.rb ) , %w( elements ** *.rb ) , %w( containers ** *.rb ) ]
55 . flat_map { |matcher | Dir . glob ( File . join ( __dir__ , 'govuk_design_system_formbuilder' , *matcher ) ) }
66 . each { |file | require file }
77
88module GOVUKDesignSystemFormBuilder
9- include ActiveSupport ::Configurable
9+ class << self
10+ class_attribute :config ,
11+ instance_predicate : false ,
12+ default : ActiveSupport ::OrderedOptions . new
13+
14+ def inherited ( klass ) # :nodoc:
15+ klass . config = ActiveSupport ::InheritableOptions . new ( config )
16+ super
17+ end
18+ end
1019
1120 # @!group Defaults
1221
@@ -133,7 +142,20 @@ module GOVUKDesignSystemFormBuilder
133142 enable_nested_localisation : true ,
134143 } . freeze
135144
136- DEFAULTS . each_key { |k | config_accessor ( k ) { DEFAULTS [ k ] } }
145+ DEFAULTS . each do |key , value |
146+ reader = "def #{ key } ; config.#{ key } ; end"
147+ reader_line = __LINE__
148+ writer = "def #{ key } =(value); config.#{ key } = value; end"
149+ writer_line = __LINE__
150+
151+ singleton_class . class_eval reader , __FILE__ , reader_line
152+ singleton_class . class_eval writer , __FILE__ , writer_line
153+
154+ class_eval reader , __FILE__ , reader_line
155+ class_eval writer , __FILE__ , writer_line
156+
157+ send ( "#{ key } =" , value )
158+ end
137159 # @!endgroup
138160
139161 class << self
@@ -146,7 +168,7 @@ class << self
146168 # conf.default_error_summary_title = 'OMG'
147169 # end
148170 def configure
149- yield ( config )
171+ yield config
150172 end
151173
152174 # Resets each of the configurable values to its default
0 commit comments