Class: ActiveRecord::Materialized::WriteChange
- Inherits:
-
Object
- Object
- ActiveRecord::Materialized::WriteChange
- Extended by:
- T::Sig
- Defined in:
- lib/activerecord/materialized/write_change.rb
Overview
A committed write to a dependency table, captured as full before/after attribute snapshots (string-keyed). Snapshots are complete — not just the changed columns — so maintenance can compute deltas even when the GROUP BY key or a summed column did not change.
Constant Summary collapse
- Operation =
T.type_alias { T.any(Symbol, String) }
- Attributes =
T.type_alias { T::Hash[String, T.untyped] }
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(table_name:, operation:, before:, after:) ⇒ WriteChange
constructor
A new instance of WriteChange.
Constructor Details
#initialize(table_name:, operation:, before:, after:) ⇒ WriteChange
Returns a new instance of WriteChange.
29 30 31 32 33 34 |
# File 'lib/activerecord/materialized/write_change.rb', line 29 def initialize(table_name:, operation:, before:, after:) @table_name = table_name @operation = operation @before = before @after = after end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
26 27 28 |
# File 'lib/activerecord/materialized/write_change.rb', line 26 def after @after end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
23 24 25 |
# File 'lib/activerecord/materialized/write_change.rb', line 23 def before @before end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
20 21 22 |
# File 'lib/activerecord/materialized/write_change.rb', line 20 def operation @operation end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
17 18 19 |
# File 'lib/activerecord/materialized/write_change.rb', line 17 def table_name @table_name end |
Class Method Details
.from_record(record, operation) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/activerecord/materialized/write_change.rb', line 37 def self.from_record(record, operation) table_name = record.class.table_name case operation.to_sym when :create new(table_name: table_name, operation: :create, before: {}, after: stringify_keys(record.attributes)) when :update new(table_name: table_name, operation: :update, before: old_attributes(record), after: stringify_keys(record.attributes)) when :destroy # attributes_in_database is emptied once the row is gone; use in-memory attributes. new(table_name: table_name, operation: :destroy, before: stringify_keys(record.attributes), after: {}) else raise ArgumentError, "unsupported write operation: #{operation}" end end |