Module: IronTrail::ChangeModelConcern::ClassMethods
- Defined in:
- lib/iron_trail/change_model_concern.rb
Instance Method Summary collapse
- #where_object_changes_from(args = {}) ⇒ Object
- #where_object_changes_to(args = {}) ⇒ Object
-
#with_delta_other_than(*columns) ⇒ Object
Allows filtering out updates that changed just a certain set of columns.
Instance Method Details
#where_object_changes_from(args = {}) ⇒ Object
56 57 58 |
# File 'lib/iron_trail/change_model_concern.rb', line 56 def where_object_changes_from(args = {}) _where_object_changes(0, args) end |
#where_object_changes_to(args = {}) ⇒ Object
52 53 54 |
# File 'lib/iron_trail/change_model_concern.rb', line 52 def where_object_changes_to(args = {}) _where_object_changes(1, args) end |
#with_delta_other_than(*columns) ⇒ Object
Allows filtering out updates that changed just a certain set of columns. This could be useful, for instance, to filter out updates made with ActiveRecord’s #touch method, which changes only the updated_at column. In that case, calling ‘.with_delta_other_than(:updated_at)` would exclude such changes from the result.
This works by inspecting whether there are any keys in the rec_delta column other than the columns specified in the ‘columns` parameter.
68 69 70 71 72 73 74 |
# File 'lib/iron_trail/change_model_concern.rb', line 68 def with_delta_other_than(*columns) quoted_columns = columns.map { |col_name| connection.quote(col_name) } exclude_array = "ARRAY[#{quoted_columns.join(', ')}]::text[]" sql = "rec_delta IS NULL OR (rec_delta - #{exclude_array}) <> '{}'::jsonb" where(::Arel::Nodes::SqlLiteral.new(sql)) end |