класс ActiveRecord::Reflection::MacroReflection
Базовый класс для AggregateReflection и AssociationReflection. Объекты AggregateReflection и AssociationReflection возвращаются методом Reflection::ClassMethods.
MacroReflection
AssociationReflection
AggregateReflection
HasManyReflection
HasOneReflection
BelongsToReflection
ThroughReflection
Атрибуты
Возвращает имя макроса.
composed_of :balance, class_name: 'Money' возвращает :balance has_many :clients возвращает :clients
Возвращает хеш опций, используемых для макроса.
composed_of :balance, class_name: 'Money' возвращает { class_name: "Money" } has_many
:clients возвращает {}
Публичные методы класса
# File activerecord/lib/active_record/reflection.rb, line 218
def initialize(name, scope, options, active_record)
@name = name
@scope = scope
@options = options
@active_record = active_record
@klass = options[:anonymous_class]
@plural_name = active_record.pluralize_table_names ?
name.to_s.pluralize : name.to_s
end Публичные методы экземпляра
# File activerecord/lib/active_record/reflection.rb, line 251
def ==(other_aggregation)
super ||
other_aggregation.kind_of?(self.class) &&
name == other_aggregation.name &&
!other_aggregation.options.nil? &&
active_record == other_aggregation.active_record
end Возвращает true , если self и other_aggregation имеют одинаковые атрибуты name, active_record и у other_aggregation задан хеш опций.
# File activerecord/lib/active_record/reflection.rb, line 228
def autosave=(autosave)
@automatic_inverse_of = false
@options[:autosave] = autosave
_, parent_reflection = self.parent_reflection
if parent_reflection
parent_reflection.autosave = autosave
end
end # File activerecord/lib/active_record/reflection.rb, line 245 def compute_class(name) name.constantize end
# File activerecord/lib/active_record/reflection.rb, line 241 def klass @klass ||= compute_class(class_name) end
Возвращает класс для макроса.
composed_of :balance, class_name: 'Money' возвращает класс Money has_many :clients возвращает класс Client
© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.