Sha256: 0c3c9be9faef15ffcdc3fb96260b6135f4b2d2b888bc05863f0b3ac121a9d949

Contents?: true

Size: 607 Bytes

Versions: 1

Compression:

Stored size: 607 Bytes

Contents

require 'active_record'

module ActiveRecord::AttributeMethods::Read
  def read_attribute(attr_name, &block) # :nodoc:
    name = attr_name.to_s
    name = self.class.attribute_aliases[name] || name

    name = @primary_key if name == 'id' && @primary_key
    _read_attribute(name, &block)
  end

  def _read_attribute(attr_name, &block) # :nodoc:
    name = attr_name.to_s
    name = self.class.attribute_aliases[name] || name

    sync_with_transaction_state if @transaction_state&.finalized?
    return yield if block_given? && !@attributes.key?(name)
    @attributes.fetch_value(name, &block)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adaptive_alias-0.0.2 lib/adaptive_alias/active_model_patches/read_attribute.rb