Class: Card::Change
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Card::Change
- Defined in:
- mod/history/lib/card/change.rb
Overview
A change is an alteration to a card's name, type, content, or trash state. Together, acts, actions, and changes comprise a comprehensive card history tracking system.
For example, if a given web submission changes both the name and type of card, that would be recorded as one action with two changes.
A Change records:
- the field changed
- the new value of that field
- the action of which the change is part
Constant Summary collapse
- TRACKED_FIELDS =
lists the database fields for which changes are recorded
%w[name type_id db_content trash].freeze
Class Method Summary collapse
- .delete_actionless ⇒ Object
-
.field_index(value) ⇒ Integer
Change fields are recorded as integers.
-
.find_by_field_name(value) ⇒ Change
look up changes based on field name.
Instance Method Summary collapse
-
#field ⇒ String
retrieve field name.
-
#field=(value) ⇒ Object
set field value (integer).
Class Method Details
.delete_actionless ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'mod/history/lib/card/change.rb', line 29 def delete_actionless joins( "LEFT JOIN card_actions "\ "ON card_changes.card_action_id = card_actions.id " ).where( "card_actions.id is null" ).pluck_in_batches(:id) do |group_ids| # used to be .delete_all here, but that was failing on large dbs Rails.logger.info "deleting batch of changes" where("id in (#{group_ids.join ','})").delete_all end end |
.field_index(value) ⇒ Integer
Change fields are recorded as integers. #field_index looks up the integer associated with a given field name.
46 47 48 |
# File 'mod/history/lib/card/change.rb', line 46 def field_index value value.is_a?(Integer) ? value : TRACKED_FIELDS.index(value.to_s) end |
.find_by_field_name(value) ⇒ Change
look up changes based on field name
53 54 55 |
# File 'mod/history/lib/card/change.rb', line 53 def find_by_field_name value find_by_field field_index(value) end |
Instance Method Details
#field ⇒ String
retrieve field name
66 67 68 |
# File 'mod/history/lib/card/change.rb', line 66 def field TRACKED_FIELDS[read_attribute(:field)] end |
#field=(value) ⇒ Object
set field value (integer)
60 61 62 |
# File 'mod/history/lib/card/change.rb', line 60 def field= value write_attribute(:field, TRACKED_FIELDS.index(value.to_s)) end |