aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/configurable.rb
diff options
context:
space:
mode:
authorthedarkone <thedarkone2@gmail.com>2010-09-27 14:50:39 +0200
committerthedarkone <thedarkone2@gmail.com>2010-09-27 17:45:58 +0200
commit918dc27345319fbabf25a43bd65b613878b3a66e (patch)
tree9384f88171b155ac6655d70c2448e4e8a364fe32 /activesupport/lib/active_support/configurable.rb
parent7918a5c96604b6c2d8a60542b7afc9e445c43fba (diff)
downloadrails-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/configurable.rb')
-rw-r--r--activesupport/lib/active_support/configurable.rb24
1 files changed, 22 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