Module: Upkeep::Runtime::AttributeObserver

Defined in:
lib/upkeep/runtime.rb

Instance Method Summary collapse

Instance Method Details

#_read_attribute(attr_name, &block) ⇒ Object



839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
# File 'lib/upkeep/runtime.rb', line 839

def _read_attribute(attr_name, &block)
  value = super
  return value unless Observation.recording?

  id = primary_key_value(attr_name, value)
  dependency = Dependencies::ActiveRecordAttribute.new(
    table: self.class.table_name,
    model: self.class.name,
    id: id,
    attribute: attr_name.to_s,
    scope: id.nil? ? upkeep_fresh_record_scope : nil
  )

  Observation.record_dependency(dependency)

  value
end