diff options
author | wycats <wycats@gmail.com> | 2010-04-26 23:32:30 -0700 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-04-26 23:32:30 -0700 |
commit | 91963e9e33eb5a28297323f1346aeb8b643e9d65 (patch) | |
tree | 0452dbaf63110fb5a19c958da50d4677dee11333 /activesupport/lib/active_support/configurable.rb | |
parent | d5d717161d853d8d7240da59b41a879bdac6e982 (diff) | |
parent | c1d73270717f30498f8f4d55d6695509107c2834 (diff) | |
download | rails-91963e9e33eb5a28297323f1346aeb8b643e9d65.tar.gz rails-91963e9e33eb5a28297323f1346aeb8b643e9d65.tar.bz2 rails-91963e9e33eb5a28297323f1346aeb8b643e9d65.zip |
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activesupport/lib/active_support/configurable.rb')
-rw-r--r-- | activesupport/lib/active_support/configurable.rb | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 890f465ce1..f562e17c75 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -1,35 +1,36 @@ -require "active_support/concern" +require 'active_support/concern' +require 'active_support/ordered_options' +require 'active_support/core_ext/kernel/singleton_class' +require 'active_support/core_ext/module/delegation' module ActiveSupport module Configurable extend ActiveSupport::Concern module ClassMethods - def get_config - module_parts = name.split("::") - modules = [Object] - module_parts.each {|name| modules.push modules.last.const_get(name) } - modules.reverse_each do |mod| - return mod.const_get(:DEFAULT_CONFIG) if const_defined?(:DEFAULT_CONFIG) - end - {} - end - def config - self.config = get_config unless @config - @config + @config ||= ActiveSupport::InheritableOptions.new(superclass.respond_to?(:config) ? superclass.config : {}) end - def config=(hash) - @config = ActiveSupport::OrderedOptions.new - hash.each do |key, value| - @config[key] = value + def configure + yield config + end + + def config_accessor(*names) + names.each do |name| + code, line = <<-RUBY, __LINE__ + 1 + def #{name}; config.#{name}; end + def #{name}=(value); config.#{name} = value; end + RUBY + + singleton_class.class_eval code, __FILE__, line + class_eval code, __FILE__, line end end end def config - self.class.config + @config ||= ActiveSupport::InheritableOptions.new(self.class.config) end end end
\ No newline at end of file |