From ba7ec73f6a5c98c008e8e48eb06e9b9a17a91991 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 23 Dec 2011 21:37:52 +0000 Subject: Deal with global config better between AR::Base and AR::Model --- activerecord/lib/active_record/configuration.rb | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 activerecord/lib/active_record/configuration.rb (limited to 'activerecord/lib/active_record/configuration.rb') 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 -- cgit v1.2.3