Class: Card::Change
- Inherits:
-
Cardio::Record
- Object
- Cardio::Record
- Card::Change
- Defined in:
- 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 left_id right_id].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
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/card/change.rb', line 30 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.
47 48 49 |
# File 'lib/card/change.rb', line 47 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
54 55 56 |
# File 'lib/card/change.rb', line 54 def find_by_field_name value find_by_field field_index(value) end |
Instance Method Details
#field ⇒ String
retrieve field name
67 68 69 |
# File 'lib/card/change.rb', line 67 def field TRACKED_FIELDS[read_attribute(:field)] end |
#field=(value) ⇒ Object
set field value (integer)
61 62 63 |
# File 'lib/card/change.rb', line 61 def field= value write_attribute(:field, TRACKED_FIELDS.index(value.to_s)) end |