aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/configuration.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/configuration.rb')
-rw-r--r--activerecord/lib/active_record/configuration.rb36
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