diff options
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/lookup_context.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb index 0bb73b590d..27ee8b23c9 100644 --- a/actionpack/lib/action_view/lookup_context.rb +++ b/actionpack/lib/action_view/lookup_context.rb @@ -13,18 +13,21 @@ module ActionView mattr_accessor :registered_details self.registered_details = [] - def self.register_detail(name, options = {}) + def self.register_detail(name, options = {}, &block) self.registered_details << name - Setters.send :define_method, :"#{name}=" do |value| - value = Array(value.presence || yield) - value |= [nil] unless options[:allow_nil] == false + Setters.send :define_method, :"_#{name}_defaults", &block + Setters.module_eval <<-METHOD, __FILE__, __LINE__ + 1 + def #{name}=(value) + value = Array(value.presence || _#{name}_defaults) + #{"value << nil unless value.include?(nil)" unless options[:allow_nil] == false} - unless value == @details[name] - @details_key, @details = nil, @details.merge(name => value) - @details.freeze + unless value == @details[:#{name}] + @details_key, @details = nil, @details.merge(:#{name} => value) + @details.freeze + end end - end + METHOD end # Holds raw setters for the registered details. |