mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
class inheritable attributes is used no more! all internal use of class inheritable has been changed to class_attribute. class inheritable attributes has been deprecated.
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
8d8062190d
commit
d7db6a8873
17 changed files with 91 additions and 55 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActionMailer
|
module ActionMailer
|
||||||
class NonInferrableMailerError < ::StandardError
|
class NonInferrableMailerError < ::StandardError
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
|
@ -15,11 +17,11 @@ module ActionMailer
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def tests(mailer)
|
def tests(mailer)
|
||||||
write_inheritable_attribute(:mailer_class, mailer)
|
self._mailer_class = mailer
|
||||||
end
|
end
|
||||||
|
|
||||||
def mailer_class
|
def mailer_class
|
||||||
if mailer = read_inheritable_attribute(:mailer_class)
|
if mailer = self._mailer_class
|
||||||
mailer
|
mailer
|
||||||
else
|
else
|
||||||
tests determine_default_mailer(name)
|
tests determine_default_mailer(name)
|
||||||
|
@ -65,6 +67,7 @@ module ActionMailer
|
||||||
end
|
end
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
class_attribute :_mailer_class
|
||||||
setup :initialize_test_deliveries
|
setup :initialize_test_deliveries
|
||||||
setup :set_expected_mail
|
setup :set_expected_mail
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'rack/session/abstract/id'
|
require 'rack/session/abstract/id'
|
||||||
require 'active_support/core_ext/object/blank'
|
require 'active_support/core_ext/object/blank'
|
||||||
require 'active_support/core_ext/object/to_query'
|
require 'active_support/core_ext/object/to_query'
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActionController
|
module ActionController
|
||||||
module TemplateAssertions
|
module TemplateAssertions
|
||||||
|
@ -325,11 +326,11 @@ module ActionController
|
||||||
|
|
||||||
def controller_class=(new_class)
|
def controller_class=(new_class)
|
||||||
prepare_controller_class(new_class) if new_class
|
prepare_controller_class(new_class) if new_class
|
||||||
write_inheritable_attribute(:controller_class, new_class)
|
self._controller_class = new_class
|
||||||
end
|
end
|
||||||
|
|
||||||
def controller_class
|
def controller_class
|
||||||
if current_controller_class = read_inheritable_attribute(:controller_class)
|
if current_controller_class = self._controller_class
|
||||||
current_controller_class
|
current_controller_class
|
||||||
else
|
else
|
||||||
self.controller_class = determine_default_controller_class(name)
|
self.controller_class = determine_default_controller_class(name)
|
||||||
|
@ -442,6 +443,7 @@ module ActionController
|
||||||
included do
|
included do
|
||||||
include ActionController::TemplateAssertions
|
include ActionController::TemplateAssertions
|
||||||
include ActionDispatch::Assertions
|
include ActionDispatch::Assertions
|
||||||
|
class_attribute :_controller_class
|
||||||
setup :setup_controller_request_and_response
|
setup :setup_controller_request_and_response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
require 'set'
|
require 'set'
|
||||||
require 'active_support/core_ext/class/inheritable_attributes'
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module HTML
|
module HTML
|
||||||
class Sanitizer
|
class Sanitizer
|
||||||
|
@ -60,7 +60,7 @@ module HTML
|
||||||
class WhiteListSanitizer < Sanitizer
|
class WhiteListSanitizer < Sanitizer
|
||||||
[:protocol_separator, :uri_attributes, :allowed_attributes, :allowed_tags, :allowed_protocols, :bad_tags,
|
[:protocol_separator, :uri_attributes, :allowed_attributes, :allowed_tags, :allowed_protocols, :bad_tags,
|
||||||
:allowed_css_properties, :allowed_css_keywords, :shorthand_css_properties].each do |attr|
|
:allowed_css_properties, :allowed_css_keywords, :shorthand_css_properties].each do |attr|
|
||||||
class_inheritable_accessor attr, :instance_writer => false
|
class_attribute attr, :instance_writer => false
|
||||||
end
|
end
|
||||||
|
|
||||||
# A regular expression of the valid characters used to separate protocols like
|
# A regular expression of the valid characters used to separate protocols like
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'cgi'
|
||||||
require 'action_view/helpers/date_helper'
|
require 'action_view/helpers/date_helper'
|
||||||
require 'action_view/helpers/tag_helper'
|
require 'action_view/helpers/tag_helper'
|
||||||
require 'action_view/helpers/form_tag_helper'
|
require 'action_view/helpers/form_tag_helper'
|
||||||
require 'active_support/core_ext/class/inheritable_attributes'
|
require 'active_support/core_ext/class/attribute'
|
||||||
require 'active_support/core_ext/hash/slice'
|
require 'active_support/core_ext/hash/slice'
|
||||||
require 'active_support/core_ext/object/blank'
|
require 'active_support/core_ext/object/blank'
|
||||||
require 'active_support/core_ext/string/output_safety'
|
require 'active_support/core_ext/string/output_safety'
|
||||||
|
@ -1117,7 +1117,7 @@ module ActionView
|
||||||
|
|
||||||
class FormBuilder #:nodoc:
|
class FormBuilder #:nodoc:
|
||||||
# The methods which wrap a form helper call.
|
# The methods which wrap a form helper call.
|
||||||
class_inheritable_accessor :field_helpers
|
class_attribute :field_helpers
|
||||||
self.field_helpers = (FormHelper.instance_method_names - ['form_for'])
|
self.field_helpers = (FormHelper.instance_method_names - ['form_for'])
|
||||||
|
|
||||||
attr_accessor :object_name, :object, :options
|
attr_accessor :object_name, :object, :options
|
||||||
|
|
|
@ -4,6 +4,7 @@ require 'active_support/core_ext/module/delegation'
|
||||||
require 'active_support/core_ext/object/blank'
|
require 'active_support/core_ext/object/blank'
|
||||||
require 'active_support/core_ext/string/conversions'
|
require 'active_support/core_ext/string/conversions'
|
||||||
require 'active_support/core_ext/module/remove_method'
|
require 'active_support/core_ext/module/remove_method'
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
|
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
|
||||||
|
@ -1810,12 +1811,12 @@ module ActiveRecord
|
||||||
callbacks.each do |callback_name|
|
callbacks.each do |callback_name|
|
||||||
full_callback_name = "#{callback_name}_for_#{association_name}"
|
full_callback_name = "#{callback_name}_for_#{association_name}"
|
||||||
defined_callbacks = options[callback_name.to_sym]
|
defined_callbacks = options[callback_name.to_sym]
|
||||||
if options.has_key?(callback_name.to_sym)
|
|
||||||
class_inheritable_reader full_callback_name.to_sym
|
full_callback_value = options.has_key?(callback_name.to_sym) ? [defined_callbacks].flatten : []
|
||||||
write_inheritable_attribute(full_callback_name.to_sym, [defined_callbacks].flatten)
|
|
||||||
else
|
# TODO : why do i need method_defined? I think its because of the inheritance chain
|
||||||
write_inheritable_attribute(full_callback_name.to_sym, [])
|
class_attribute full_callback_name.to_sym unless method_defined?(full_callback_name)
|
||||||
end
|
self.send("#{full_callback_name}=", full_callback_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -530,7 +530,7 @@ module ActiveRecord
|
||||||
|
|
||||||
def callbacks_for(callback_name)
|
def callbacks_for(callback_name)
|
||||||
full_callback_name = "#{callback_name}_for_#{@reflection.name}"
|
full_callback_name = "#{callback_name}_for_#{@reflection.name}"
|
||||||
@owner.class.read_inheritable_attribute(full_callback_name.to_sym) || []
|
@owner.class.send(full_callback_name.to_sym) || []
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_owner_is_not_new
|
def ensure_owner_is_not_new
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
require 'active_support/core_ext/object/blank'
|
require 'active_support/core_ext/object/blank'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
|
@ -88,7 +89,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def clone_with_time_zone_conversion_attribute?(attr, old)
|
def clone_with_time_zone_conversion_attribute?(attr, old)
|
||||||
old.class.name == "Time" && time_zone_aware_attributes && !skip_time_zone_conversion_for_attributes.include?(attr.to_sym)
|
old.class.name == "Time" && time_zone_aware_attributes && !self.skip_time_zone_conversion_for_attributes.include?(attr.to_sym)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
module AttributeMethods
|
module AttributeMethods
|
||||||
module TimeZoneConversion
|
module TimeZoneConversion
|
||||||
|
@ -7,7 +9,7 @@ module ActiveRecord
|
||||||
cattr_accessor :time_zone_aware_attributes, :instance_writer => false
|
cattr_accessor :time_zone_aware_attributes, :instance_writer => false
|
||||||
self.time_zone_aware_attributes = false
|
self.time_zone_aware_attributes = false
|
||||||
|
|
||||||
class_inheritable_accessor :skip_time_zone_conversion_for_attributes, :instance_writer => false
|
class_attribute :skip_time_zone_conversion_for_attributes, :instance_writer => false
|
||||||
self.skip_time_zone_conversion_for_attributes = []
|
self.skip_time_zone_conversion_for_attributes = []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,7 +56,7 @@ module ActiveRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
def create_time_zone_conversion_attribute?(name, column)
|
def create_time_zone_conversion_attribute?(name, column)
|
||||||
time_zone_aware_attributes && !skip_time_zone_conversion_for_attributes.include?(name.to_sym) && [:datetime, :timestamp].include?(column.type)
|
time_zone_aware_attributes && !self.skip_time_zone_conversion_for_attributes.include?(name.to_sym) && [:datetime, :timestamp].include?(column.type)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ require 'active_support/time'
|
||||||
require 'active_support/core_ext/class/attribute'
|
require 'active_support/core_ext/class/attribute'
|
||||||
require 'active_support/core_ext/class/attribute_accessors'
|
require 'active_support/core_ext/class/attribute_accessors'
|
||||||
require 'active_support/core_ext/class/delegating_attributes'
|
require 'active_support/core_ext/class/delegating_attributes'
|
||||||
require 'active_support/core_ext/class/inheritable_attributes'
|
require 'active_support/core_ext/class/attribute'
|
||||||
require 'active_support/core_ext/array/extract_options'
|
require 'active_support/core_ext/array/extract_options'
|
||||||
require 'active_support/core_ext/hash/deep_merge'
|
require 'active_support/core_ext/hash/deep_merge'
|
||||||
require 'active_support/core_ext/hash/indifferent_access'
|
require 'active_support/core_ext/hash/indifferent_access'
|
||||||
|
@ -412,7 +412,7 @@ module ActiveRecord #:nodoc:
|
||||||
self.store_full_sti_class = true
|
self.store_full_sti_class = true
|
||||||
|
|
||||||
# Stores the default scope for the class
|
# Stores the default scope for the class
|
||||||
class_inheritable_accessor :default_scoping, :instance_writer => false
|
class_attribute :default_scoping, :instance_writer => false
|
||||||
self.default_scoping = []
|
self.default_scoping = []
|
||||||
|
|
||||||
# Returns a hash of all the attributes that have been specified for serialization as
|
# Returns a hash of all the attributes that have been specified for serialization as
|
||||||
|
@ -420,6 +420,9 @@ module ActiveRecord #:nodoc:
|
||||||
class_attribute :serialized_attributes
|
class_attribute :serialized_attributes
|
||||||
self.serialized_attributes = {}
|
self.serialized_attributes = {}
|
||||||
|
|
||||||
|
class_attribute :_attr_readonly, :instance_writer => false
|
||||||
|
self._attr_readonly = []
|
||||||
|
|
||||||
class << self # Class methods
|
class << self # Class methods
|
||||||
delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :update, :update_all, :to => :scoped
|
delegate :find, :first, :last, :all, :destroy, :destroy_all, :exists?, :delete, :delete_all, :update, :update_all, :to => :scoped
|
||||||
delegate :find_each, :find_in_batches, :to => :scoped
|
delegate :find_each, :find_in_batches, :to => :scoped
|
||||||
|
@ -504,12 +507,12 @@ module ActiveRecord #:nodoc:
|
||||||
# Attributes listed as readonly will be used to create a new record but update operations will
|
# Attributes listed as readonly will be used to create a new record but update operations will
|
||||||
# ignore these fields.
|
# ignore these fields.
|
||||||
def attr_readonly(*attributes)
|
def attr_readonly(*attributes)
|
||||||
write_inheritable_attribute(:attr_readonly, Set.new(attributes.map { |a| a.to_s }) + (readonly_attributes || []))
|
self._attr_readonly = Set.new(attributes.map { |a| a.to_s }) + (self._attr_readonly || [])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of all the attributes that have been specified as readonly.
|
# Returns an array of all the attributes that have been specified as readonly.
|
||||||
def readonly_attributes
|
def readonly_attributes
|
||||||
read_inheritable_attribute(:attr_readonly) || []
|
self._attr_readonly
|
||||||
end
|
end
|
||||||
|
|
||||||
# If you have an attribute that needs to be saved to the database as an object, and retrieved as the same object,
|
# If you have an attribute that needs to be saved to the database as an object, and retrieved as the same object,
|
||||||
|
@ -724,8 +727,8 @@ module ActiveRecord #:nodoc:
|
||||||
@arel_engine = @relation = @arel_table = nil
|
@arel_engine = @relation = @arel_table = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodoc:
|
def reset_column_information_for_all_subclasses#:nodoc:
|
||||||
descendants.each { |klass| klass.reset_inheritable_attributes; klass.reset_column_information }
|
descendants.each { |klass| klass.reset_column_information }
|
||||||
end
|
end
|
||||||
|
|
||||||
def attribute_method?(attribute)
|
def attribute_method?(attribute)
|
||||||
|
@ -1126,7 +1129,8 @@ MSG
|
||||||
# Article.create.published # => true
|
# Article.create.published # => true
|
||||||
def default_scope(options = {})
|
def default_scope(options = {})
|
||||||
reset_scoped_methods
|
reset_scoped_methods
|
||||||
self.default_scoping << construct_finder_arel(options, default_scoping.pop)
|
default_scoping = self.default_scoping.dup
|
||||||
|
self.default_scoping = default_scoping << construct_finder_arel(options, default_scoping.pop)
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_scoped_methods #:nodoc:
|
def current_scoped_methods #:nodoc:
|
||||||
|
|
|
@ -2,12 +2,18 @@ require 'active_support/core_ext/array'
|
||||||
require 'active_support/core_ext/hash/except'
|
require 'active_support/core_ext/hash/except'
|
||||||
require 'active_support/core_ext/kernel/singleton_class'
|
require 'active_support/core_ext/kernel/singleton_class'
|
||||||
require 'active_support/core_ext/object/blank'
|
require 'active_support/core_ext/object/blank'
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
# = Active Record Named \Scopes
|
# = Active Record Named \Scopes
|
||||||
module NamedScope
|
module NamedScope
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
class_attribute :scopes
|
||||||
|
self.scopes = {}
|
||||||
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# Returns an anonymous \scope.
|
# Returns an anonymous \scope.
|
||||||
#
|
#
|
||||||
|
@ -33,10 +39,6 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def scopes
|
|
||||||
read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {})
|
|
||||||
end
|
|
||||||
|
|
||||||
# Adds a class method for retrieving and querying objects. A \scope represents a narrowing of a database query,
|
# Adds a class method for retrieving and querying objects. A \scope represents a narrowing of a database query,
|
||||||
# such as <tt>where(:color => :red).select('shirts.*').includes(:washing_instructions)</tt>.
|
# such as <tt>where(:color => :red).select('shirts.*').includes(:washing_instructions)</tt>.
|
||||||
#
|
#
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'active_support/core_ext/hash/except'
|
||||||
require 'active_support/core_ext/object/try'
|
require 'active_support/core_ext/object/try'
|
||||||
require 'active_support/core_ext/object/blank'
|
require 'active_support/core_ext/object/blank'
|
||||||
require 'active_support/core_ext/hash/indifferent_access'
|
require 'active_support/core_ext/hash/indifferent_access'
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
module NestedAttributes #:nodoc:
|
module NestedAttributes #:nodoc:
|
||||||
|
@ -11,7 +12,7 @@ module ActiveRecord
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
class_inheritable_accessor :nested_attributes_options, :instance_writer => false
|
class_attribute :nested_attributes_options, :instance_writer => false
|
||||||
self.nested_attributes_options = {}
|
self.nested_attributes_options = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -268,7 +269,11 @@ module ActiveRecord
|
||||||
if reflection = reflect_on_association(association_name)
|
if reflection = reflect_on_association(association_name)
|
||||||
reflection.options[:autosave] = true
|
reflection.options[:autosave] = true
|
||||||
add_autosave_association_callbacks(reflection)
|
add_autosave_association_callbacks(reflection)
|
||||||
|
|
||||||
|
nested_attributes_options = self.nested_attributes_options.dup
|
||||||
nested_attributes_options[association_name.to_sym] = options
|
nested_attributes_options[association_name.to_sym] = options
|
||||||
|
self.nested_attributes_options = nested_attributes_options
|
||||||
|
|
||||||
type = (reflection.collection? ? :collection : :one_to_one)
|
type = (reflection.collection? ? :collection : :one_to_one)
|
||||||
|
|
||||||
# def pirate_attributes=(attributes)
|
# def pirate_attributes=(attributes)
|
||||||
|
@ -315,7 +320,7 @@ module ActiveRecord
|
||||||
# update_only is true, and a <tt>:_destroy</tt> key set to a truthy value,
|
# update_only is true, and a <tt>:_destroy</tt> key set to a truthy value,
|
||||||
# then the existing record will be marked for destruction.
|
# then the existing record will be marked for destruction.
|
||||||
def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
|
def assign_nested_attributes_for_one_to_one_association(association_name, attributes)
|
||||||
options = nested_attributes_options[association_name]
|
options = self.nested_attributes_options[association_name]
|
||||||
attributes = attributes.with_indifferent_access
|
attributes = attributes.with_indifferent_access
|
||||||
check_existing_record = (options[:update_only] || !attributes['id'].blank?)
|
check_existing_record = (options[:update_only] || !attributes['id'].blank?)
|
||||||
|
|
||||||
|
@ -364,7 +369,7 @@ module ActiveRecord
|
||||||
# { :id => '2', :_destroy => true }
|
# { :id => '2', :_destroy => true }
|
||||||
# ])
|
# ])
|
||||||
def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
|
def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
|
||||||
options = nested_attributes_options[association_name]
|
options = self.nested_attributes_options[association_name]
|
||||||
|
|
||||||
unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
|
unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
|
||||||
raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
|
raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
|
||||||
|
@ -433,7 +438,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def call_reject_if(association_name, attributes)
|
def call_reject_if(association_name, attributes)
|
||||||
case callback = nested_attributes_options[association_name][:reject_if]
|
case callback = self.nested_attributes_options[association_name][:reject_if]
|
||||||
when Symbol
|
when Symbol
|
||||||
method(callback).arity == 0 ? send(callback) : send(callback, attributes)
|
method(callback).arity == 0 ? send(callback) : send(callback, attributes)
|
||||||
when Proc
|
when Proc
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
# = Active Record Reflection
|
# = Active Record Reflection
|
||||||
module Reflection # :nodoc:
|
module Reflection # :nodoc:
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
class_attribute :reflections
|
||||||
|
self.reflections = {}
|
||||||
|
end
|
||||||
|
|
||||||
# Reflection enables to interrogate Active Record classes and objects
|
# Reflection enables to interrogate Active Record classes and objects
|
||||||
# about their associations and aggregations. This information can,
|
# about their associations and aggregations. This information can,
|
||||||
# for example, be used in a form builder that takes an Active Record object
|
# for example, be used in a form builder that takes an Active Record object
|
||||||
|
@ -20,18 +27,9 @@ module ActiveRecord
|
||||||
when :composed_of
|
when :composed_of
|
||||||
reflection = AggregateReflection.new(macro, name, options, active_record)
|
reflection = AggregateReflection.new(macro, name, options, active_record)
|
||||||
end
|
end
|
||||||
write_inheritable_hash :reflections, name => reflection
|
|
||||||
reflection
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns a hash containing all AssociationReflection objects for the current class.
|
self.reflections = self.reflections.merge(name => reflection)
|
||||||
# Example:
|
reflection
|
||||||
#
|
|
||||||
# Invoice.reflections
|
|
||||||
# Account.reflections
|
|
||||||
#
|
|
||||||
def reflections
|
|
||||||
read_inheritable_attribute(:reflections) || write_inheritable_attribute(:reflections, {})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of AggregateReflection objects for all the aggregations in the class.
|
# Returns an array of AggregateReflection objects for all the aggregations in the class.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'active_support/core_ext/class/attribute'
|
||||||
|
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
# = Active Record Timestamp
|
# = Active Record Timestamp
|
||||||
#
|
#
|
||||||
|
@ -29,14 +31,14 @@ module ActiveRecord
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
class_inheritable_accessor :record_timestamps, :instance_writer => false
|
class_attribute :record_timestamps, :instance_writer => false
|
||||||
self.record_timestamps = true
|
self.record_timestamps = true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create #:nodoc:
|
def create #:nodoc:
|
||||||
if record_timestamps
|
if self.record_timestamps
|
||||||
current_time = current_time_from_proper_timezone
|
current_time = current_time_from_proper_timezone
|
||||||
|
|
||||||
all_timestamp_attributes.each do |column|
|
all_timestamp_attributes.each do |column|
|
||||||
|
@ -61,7 +63,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_record_timestamps?
|
def should_record_timestamps?
|
||||||
record_timestamps && (!partial_updates? || changed? || (attributes.keys & self.class.serialized_attributes.keys).present?)
|
self.record_timestamps && (!partial_updates? || changed? || (attributes.keys & self.class.serialized_attributes.keys).present?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def timestamp_attributes_for_update_in_model
|
def timestamp_attributes_for_update_in_model
|
||||||
|
|
|
@ -270,17 +270,17 @@ class OverridingAssociationsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
def test_habtm_association_redefinition_callbacks_should_differ_and_not_inherited
|
def test_habtm_association_redefinition_callbacks_should_differ_and_not_inherited
|
||||||
# redeclared association on AR descendant should not inherit callbacks from superclass
|
# redeclared association on AR descendant should not inherit callbacks from superclass
|
||||||
callbacks = PeopleList.read_inheritable_attribute(:before_add_for_has_and_belongs_to_many)
|
callbacks = PeopleList.before_add_for_has_and_belongs_to_many
|
||||||
assert_equal([:enlist], callbacks)
|
assert_equal([:enlist], callbacks)
|
||||||
callbacks = DifferentPeopleList.read_inheritable_attribute(:before_add_for_has_and_belongs_to_many)
|
callbacks = DifferentPeopleList.before_add_for_has_and_belongs_to_many
|
||||||
assert_equal([], callbacks)
|
assert_equal([], callbacks)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_has_many_association_redefinition_callbacks_should_differ_and_not_inherited
|
def test_has_many_association_redefinition_callbacks_should_differ_and_not_inherited
|
||||||
# redeclared association on AR descendant should not inherit callbacks from superclass
|
# redeclared association on AR descendant should not inherit callbacks from superclass
|
||||||
callbacks = PeopleList.read_inheritable_attribute(:before_add_for_has_many)
|
callbacks = PeopleList.before_add_for_has_many
|
||||||
assert_equal([:enlist], callbacks)
|
assert_equal([:enlist], callbacks)
|
||||||
callbacks = DifferentPeopleList.read_inheritable_attribute(:before_add_for_has_many)
|
callbacks = DifferentPeopleList.before_add_for_has_many
|
||||||
assert_equal([], callbacks)
|
assert_equal([], callbacks)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'active_support'
|
require 'active_support'
|
||||||
require 'active_support/core_ext/class/attribute_accessors'
|
require 'active_support/core_ext/class/attribute_accessors'
|
||||||
require 'active_support/core_ext/class/inheritable_attributes'
|
require 'active_support/core_ext/class/attribute'
|
||||||
require 'active_support/core_ext/hash/indifferent_access'
|
require 'active_support/core_ext/hash/indifferent_access'
|
||||||
require 'active_support/core_ext/kernel/reporting'
|
require 'active_support/core_ext/kernel/reporting'
|
||||||
require 'active_support/core_ext/module/attr_accessor_with_default'
|
require 'active_support/core_ext/module/attr_accessor_with_default'
|
||||||
|
@ -263,6 +263,8 @@ module ActiveResource
|
||||||
# The logger for diagnosing and tracing Active Resource calls.
|
# The logger for diagnosing and tracing Active Resource calls.
|
||||||
cattr_accessor :logger
|
cattr_accessor :logger
|
||||||
|
|
||||||
|
class_attribute :_format
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# Creates a schema for this resource - setting the attributes that are
|
# Creates a schema for this resource - setting the attributes that are
|
||||||
# known prior to fetching an instance from the remote system.
|
# known prior to fetching an instance from the remote system.
|
||||||
|
@ -492,13 +494,13 @@ module ActiveResource
|
||||||
format = mime_type_reference_or_format.is_a?(Symbol) ?
|
format = mime_type_reference_or_format.is_a?(Symbol) ?
|
||||||
ActiveResource::Formats[mime_type_reference_or_format] : mime_type_reference_or_format
|
ActiveResource::Formats[mime_type_reference_or_format] : mime_type_reference_or_format
|
||||||
|
|
||||||
write_inheritable_attribute(:format, format)
|
self._format = format
|
||||||
connection.format = format if site
|
connection.format = format if site
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the current format, default is ActiveResource::Formats::XmlFormat.
|
# Returns the current format, default is ActiveResource::Formats::XmlFormat.
|
||||||
def format
|
def format
|
||||||
read_inheritable_attribute(:format) || ActiveResource::Formats::XmlFormat
|
self._format || ActiveResource::Formats::XmlFormat
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the number of seconds after which requests to the REST API should time out.
|
# Sets the number of seconds after which requests to the REST API should time out.
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
require 'active_support/core_ext/object/duplicable'
|
require 'active_support/core_ext/object/duplicable'
|
||||||
require 'active_support/core_ext/array/extract_options'
|
require 'active_support/core_ext/array/extract_options'
|
||||||
|
require 'active_support/deprecation'
|
||||||
|
|
||||||
# Retained for backward compatibility. Methods are now included in Class.
|
# Retained for backward compatibility. Methods are now included in Class.
|
||||||
module ClassInheritableAttributes # :nodoc:
|
module ClassInheritableAttributes # :nodoc:
|
||||||
|
DEPRECATION_WARNING_MESSAGE = "class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first"
|
||||||
end
|
end
|
||||||
|
|
||||||
# It is recommended to use <tt>class_attribute</tt> over methods defined in this file. Please
|
# It is recommended to use <tt>class_attribute</tt> over methods defined in this file. Please
|
||||||
|
@ -36,6 +38,7 @@ end
|
||||||
# Person.new.hair_colors # => NoMethodError
|
# Person.new.hair_colors # => NoMethodError
|
||||||
class Class # :nodoc:
|
class Class # :nodoc:
|
||||||
def class_inheritable_reader(*syms)
|
def class_inheritable_reader(*syms)
|
||||||
|
ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
|
||||||
options = syms.extract_options!
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
next if sym.is_a?(Hash)
|
next if sym.is_a?(Hash)
|
||||||
|
@ -54,6 +57,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_inheritable_writer(*syms)
|
def class_inheritable_writer(*syms)
|
||||||
|
ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
|
||||||
options = syms.extract_options!
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||||
|
@ -71,6 +75,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_inheritable_array_writer(*syms)
|
def class_inheritable_array_writer(*syms)
|
||||||
|
ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
|
||||||
options = syms.extract_options!
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||||
|
@ -88,6 +93,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_inheritable_hash_writer(*syms)
|
def class_inheritable_hash_writer(*syms)
|
||||||
|
ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
|
||||||
options = syms.extract_options!
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
||||||
|
@ -124,6 +130,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_inheritable_attribute(key, value)
|
def write_inheritable_attribute(key, value)
|
||||||
|
ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
|
||||||
if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
|
if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
|
||||||
@inheritable_attributes = {}
|
@inheritable_attributes = {}
|
||||||
end
|
end
|
||||||
|
@ -141,10 +148,12 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_inheritable_attribute(key)
|
def read_inheritable_attribute(key)
|
||||||
|
ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
|
||||||
inheritable_attributes[key]
|
inheritable_attributes[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_inheritable_attributes
|
def reset_inheritable_attributes
|
||||||
|
ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
|
||||||
@inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
|
@inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,14 @@ require 'active_support/core_ext/class/inheritable_attributes'
|
||||||
|
|
||||||
class ClassInheritableAttributesTest < Test::Unit::TestCase
|
class ClassInheritableAttributesTest < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
|
ActiveSupport::Deprecation.silenced = true
|
||||||
@klass = Class.new
|
@klass = Class.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
ActiveSupport::Deprecation.silenced = false
|
||||||
|
end
|
||||||
|
|
||||||
def test_reader_declaration
|
def test_reader_declaration
|
||||||
assert_nothing_raised do
|
assert_nothing_raised do
|
||||||
@klass.class_inheritable_reader :a
|
@klass.class_inheritable_reader :a
|
||||||
|
|
Loading…
Reference in a new issue