модуль ActiveRecord::AttributeMethods::Read
Методы атрибутов Active Record Чтение
Публичные методы экземпляра
# File activerecord/lib/active_record/attribute_methods/read.rb, line 29
def read_attribute(attr_name, &block)
name = attr_name.to_s
name = self.class.attribute_aliases[name] || name
return @attributes.fetch_value(name, &block) unless name == "id" && @primary_key
if self.class.composite_primary_key?
@attributes.fetch_value("id", &block)
else
if @primary_key != "id"
ActiveRecord.deprecator.warn(<<-MSG.squish)
Using read_attribute(:id) to read the primary key value is deprecated.
Use #id instead.
MSG
end
@attributes.fetch_value(@primary_key, &block)
end
end Возвращает значение атрибута, идентифицированного по attr_name, после приведения его к соответствующему типу. Например, атрибут даты «2004-12-12» будет преобразован в Date.new(2004, 12, 12). (Подробнее о поведении приведения типов см. типы в ActiveModel::Type.)
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.