diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-12-23 21:37:52 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-12-24 11:08:15 +0000 |
commit | ba7ec73f6a5c98c008e8e48eb06e9b9a17a91991 (patch) | |
tree | 32501c519056e017537da0c80c9a8e787cb211b4 /activerecord/lib/active_record/configuration.rb | |
parent | 8c67e709d0b2946473af84959deaac0ced962d5e (diff) | |
download | rails-ba7ec73f6a5c98c008e8e48eb06e9b9a17a91991.tar.gz rails-ba7ec73f6a5c98c008e8e48eb06e9b9a17a91991.tar.bz2 rails-ba7ec73f6a5c98c008e8e48eb06e9b9a17a91991.zip |
Deal with global config better between AR::Base and AR::Model
Diffstat (limited to 'activerecord/lib/active_record/configuration.rb')
-rw-r--r-- | activerecord/lib/active_record/configuration.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/configuration.rb b/activerecord/lib/active_record/configuration.rb new file mode 100644 index 0000000000..d58ed82258 --- /dev/null +++ b/activerecord/lib/active_record/configuration.rb @@ -0,0 +1,36 @@ +require 'active_support/concern' + +module ActiveRecord + # This module allows configuration options to be specified in a way such that + # ActiveRecord::Base and ActiveRecord::Model will have access to the same value, + # and will automatically get the appropriate readers and writers defined. + # + # In the future, we should probably move away from defining global config + # directly on ActiveRecord::Base / ActiveRecord::Model. + module Configuration #:nodoc: + extend ActiveSupport::Concern + + module ClassMethods + end + + def self.define(name, default = nil) + singleton_class.send(:attr_accessor, name) + + [self, ClassMethods].each do |klass| + klass.class_eval <<-CODE, __FILE__, __LINE__ + def #{name} + ActiveRecord::Configuration.#{name} + end + CODE + end + + ClassMethods.class_eval <<-CODE, __FILE__, __LINE__ + def #{name}=(val) + ActiveRecord::Configuration.#{name} = val + end + CODE + + send("#{name}=", default) unless default.nil? + end + end +end |