aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/configurable.rb
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-10-14 11:59:00 -0700
committerYehuda Katz <wycats@gmail.com>2009-10-14 13:36:41 -0700
commita41c6c35cadf75bfd4bf0a17113ae37d628896e8 (patch)
tree2fd868ac1a5a4674f5a6960c931b96d6cbda48f4 /activesupport/lib/active_support/configurable.rb
parenta8dc9fd27b845193fd209a249e084f993a10c19d (diff)
downloadrails-a41c6c35cadf75bfd4bf0a17113ae37d628896e8.tar.gz
rails-a41c6c35cadf75bfd4bf0a17113ae37d628896e8.tar.bz2
rails-a41c6c35cadf75bfd4bf0a17113ae37d628896e8.zip
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)
Diffstat (limited to 'activesupport/lib/active_support/configurable.rb')
-rw-r--r--activesupport/lib/active_support/configurable.rb35
1 files changed, 35 insertions, 0 deletions
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