From a41c6c35cadf75bfd4bf0a17113ae37d628896e8 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 14 Oct 2009 11:59:00 -0700 Subject: Start adding configuration to ActionView instead of using constants. By using config rather than hardcoded constants, we can evolve the configuration system over time (we'd just need to update the config method with more robust capabilities and all consumers would get the capabilities with no code changes) --- activesupport/lib/active_support/autoload.rb | 2 ++ activesupport/lib/active_support/configurable.rb | 35 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 activesupport/lib/active_support/configurable.rb (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/autoload.rb b/activesupport/lib/active_support/autoload.rb index 47a17687bf..f3a68b482f 100644 --- a/activesupport/lib/active_support/autoload.rb +++ b/activesupport/lib/active_support/autoload.rb @@ -7,6 +7,8 @@ module ActiveSupport autoload :Callbacks, 'active_support/callbacks' autoload :Concern, 'active_support/concern' autoload :ConcurrentHash, 'active_support/concurrent_hash' + autoload :Configurable, 'active_support/configurable' + autoload :DependencyModule, 'active_support/dependency_module' autoload :DeprecatedCallbacks, 'active_support/deprecated_callbacks' autoload :Deprecation, 'active_support/deprecation' autoload :Gzip, 'active_support/gzip' diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb new file mode 100644 index 0000000000..890f465ce1 --- /dev/null +++ b/activesupport/lib/active_support/configurable.rb @@ -0,0 +1,35 @@ +require "active_support/concern" + +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 + end + + def config=(hash) + @config = ActiveSupport::OrderedOptions.new + hash.each do |key, value| + @config[key] = value + end + end + end + + def config + self.class.config + end + end +end \ No newline at end of file -- cgit v1.2.3