diff options
author | thedarkone <thedarkone2@gmail.com> | 2010-09-27 14:50:39 +0200 |
---|---|---|
committer | thedarkone <thedarkone2@gmail.com> | 2010-09-27 17:45:58 +0200 |
commit | 918dc27345319fbabf25a43bd65b613878b3a66e (patch) | |
tree | 9384f88171b155ac6655d70c2448e4e8a364fe32 /activesupport/lib/active_support | |
parent | 7918a5c96604b6c2d8a60542b7afc9e445c43fba (diff) | |
download | rails-918dc27345319fbabf25a43bd65b613878b3a66e.tar.gz rails-918dc27345319fbabf25a43bd65b613878b3a66e.tar.bz2 rails-918dc27345319fbabf25a43bd65b613878b3a66e.zip |
Compile ActionController::Base.config's methods to avoid method_missing overhead.
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/configurable.rb | 24 | ||||
-rw-r--r-- | activesupport/lib/active_support/ordered_options.rb | 4 |
2 files changed, 26 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 5b85f9394a..36634bd7f3 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -9,9 +9,29 @@ module ActiveSupport module Configurable extend ActiveSupport::Concern + class Configuration < ActiveSupport::InheritableOptions + def crystalize! + self.class.crystalize!(keys.reject {|key| respond_to?(key)}) + end + + # compiles reader methods so we don't have to go through method_missing + def self.crystalize!(keys) + keys.each do |key| + class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def #{key}; self[#{key.inspect}]; end + RUBY + end + end + end + module ClassMethods def config - @_config ||= ActiveSupport::InheritableOptions.new(superclass.respond_to?(:config) ? superclass.config : {}) + @_config ||= if superclass.respond_to?(:config) + superclass.config.inheritable_copy + else + # create a new "anonymous" class that will host the compiled reader methods + Class.new(Configuration).new({}) + end end def configure @@ -48,7 +68,7 @@ module ActiveSupport # user.config.level # => 1 # def config - @_config ||= ActiveSupport::InheritableOptions.new(self.class.config) + @_config ||= self.class.config.inheritable_copy end end end diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 37e357552c..2b67e72cff 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -39,5 +39,9 @@ module ActiveSupport #:nodoc: def initialize(parent) super() { |h,k| parent[k] } end + + def inheritable_copy + self.class.new(self) + end end end |