Module: Upkeep::Runtime::PersistenceObserver

Defined in:
lib/upkeep/runtime.rb

Instance Method Summary collapse

Instance Method Details

#touch(*names, **options) ⇒ Object



937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
# File 'lib/upkeep/runtime.rb', line 937

def touch(*names, **options)
  changed_attributes = upkeep_touch_column_names(names)

  super.tap do |result|
    if result && changed_attributes.any?
      ChangeLog.record(
        ChangeEvents.active_record_update_columns(
          self,
          changed_attributes: changed_attributes,
          new_values: upkeep_touch_column_values(changed_attributes)
        )
      )
    end
  end
end

#update_columns(attributes) ⇒ Object



953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
# File 'lib/upkeep/runtime.rb', line 953

def update_columns(attributes)
  new_values = upkeep_update_column_values(attributes)
  changed_attributes = new_values.keys

  super.tap do |result|
    if result
      ChangeLog.record(
        ChangeEvents.active_record_update_columns(
          self,
          changed_attributes: changed_attributes,
          new_values: new_values
        )
      )
    end
  end
end