Spec-Zone.ru › Ruby on Rails 4.1

класс ActiveRecord::Reflection::MacroReflection

Родитель:
Объект

Базовый класс для AggregateReflection и AssociationReflection. Объекты AggregateReflection и AssociationReflection возвращаются методом Reflection::ClassMethods.

MacroReflection
  AggregateReflection
  AssociationReflection
    ThroughReflection

Атрибуты

active_record[Ч]
macro[Ч]

Возвращает тип макроса.

composed_of :balance, class_name: 'Money' возвращает :composed_of has_many :clients возвращает :has_many

name[Ч]

Возвращает имя макроса.

composed_of :balance, class_name: 'Money' возвращает :balance has_many :clients возвращает :clients

options[Ч]

Возвращает хеш опций, используемых для макроса.

composed_of :balance, class_name: 'Money' возвращает { class_name: "Money" } has_many :clients возвращает {}

scope[Ч]

Публичные методы класса

new(macro, name, scope, options, active_record) Показать исходный код
# File activerecord/lib/active_record/reflection.rb, line 143
def initialize(macro, name, scope, options, active_record)
  @macro         = macro
  @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

Публичные методы экземпляра

==(other_aggregation) Показать исходный код

Возвращает true если self и other_aggregation имеют одинаковый атрибут name, атрибут active_record и other_aggregation имеет заданный хеш опций.

Вызов метода суперкласса
# File activerecord/lib/active_record/reflection.rb, line 181
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
autosave=(autosave) Показать исходный код
# File activerecord/lib/active_record/reflection.rb, line 154
def autosave=(autosave)
  @automatic_inverse_of = false
  @options[:autosave] = autosave
  _, parent_reflection = self.parent_reflection
  if parent_reflection
    parent_reflection.autosave = autosave
  end
end
class_name() Показать исходный код

Возвращает имя класса для макроса.

composed_of :balance, class_name: 'Money' возвращает 'Money' has_many :clients возвращает 'Client'

# File activerecord/lib/active_record/reflection.rb, line 175
def class_name
  @class_name ||= (options[:class_name] || derive_class_name).to_s
end
klass() Показать исходный код

Возвращает класс для макроса.

composed_of :balance, class_name: 'Money' возвращает класс Money has_many :clients возвращает класс Client

# File activerecord/lib/active_record/reflection.rb, line 167
def klass
  @klass ||= class_name.constantize
end

© 2004–2016 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API