diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2016-02-11 15:42:45 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2016-02-11 15:43:25 -0800 |
commit | 737b718ea0c88d3f6c139343f957f386e06fffc9 (patch) | |
tree | b2240789f0c667997b914bca9bd5896d47ca1a68 | |
parent | 448276651c7560e02ad5f89816d777fe20ef9f04 (diff) | |
download | rails-737b718ea0c88d3f6c139343f957f386e06fffc9.tar.gz rails-737b718ea0c88d3f6c139343f957f386e06fffc9.tar.bz2 rails-737b718ea0c88d3f6c139343f957f386e06fffc9.zip |
remove detail initialization metaprogramming
This metaprogrammed method doesn't seem to be a bottleneck, so lets just
use a regular method so it's easier to understand. We can follow up
with more interesting techniques for cache manipulation soon.
-rw-r--r-- | actionview/lib/action_view/lookup_context.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index 6a76d80c47..126f289f55 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -22,7 +22,7 @@ module ActionView def self.register_detail(name, &block) self.registered_details << name - initialize = registered_details.map { |n| "@details[:#{n}] = details[:#{n}] || default_#{n}" } + Accessors::DEFAULT_PROCS[name] = block Accessors.send :define_method, :"default_#{name}", &block Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1 @@ -34,16 +34,12 @@ module ActionView value = value.present? ? Array(value) : default_#{name} _set_detail(:#{name}, value) if value != @details[:#{name}] end - - remove_possible_method :initialize_details - def initialize_details(details) - #{initialize.join("\n")} - end METHOD end # Holds accessors for the registered details. module Accessors #:nodoc: + DEFAULT_PROCS = {} end register_detail(:locale) do @@ -195,15 +191,23 @@ module ActionView include ViewPaths def initialize(view_paths, details = {}, prefixes = []) - @details, @details_key = {}, nil + @details_key = nil @cache = true @prefixes = prefixes @rendered_format = nil + @details = initialize_details({}, details) self.view_paths = view_paths - initialize_details(details) end + def initialize_details(target, details) + registered_details.each do |k| + target[k] = details[k] || Accessors::DEFAULT_PROCS[k].call + end + target + end + private :initialize_details + # Override formats= to expand ["*/*"] values and automatically # add :html as fallback to :js. def formats=(values) |