Module: AdaptiveAlias::ActiveModelPatches::ReadAttribute

Included in:
ActiveRecord::Base
Defined in:
lib/adaptive_alias/active_model_patches/read_attribute.rb

Instance Method Summary collapse

Instance Method Details

#_read_attribute(attr_name, &block) ⇒ Object

This method exists to avoid the expensive primary_key check internally, without breaking compatibility with the write_attribute API



16
17
18
19
20
21
22
23
# File 'lib/adaptive_alias/active_model_patches/read_attribute.rb', line 16

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?
  attribute_set_fix!
  return @attributes.fetch_value(name, &block)
end

#read_attribute(attr_name, &block) ⇒ Object

:nodoc:



6
7
8
9
10
11
12
# File 'lib/adaptive_alias/active_model_patches/read_attribute.rb', line 6

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