class Card::Change

A change is an alteration to a card's name, type, content, or trash state. Together, {Act acts}, {Action actions}, and {Change changes} comprise a comprehensive {Card 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 action} with two {Change changes}.

A {Change} records:

Constants

TRACKED_FIELDS

lists the database fields for which changes are recorded

Public Class Methods

delete_actionless() click to toggle source

delete all {Change changes} not associated with an {Action action} (janitorial)

# File 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) click to toggle source

Change fields are recorded as integers. field_index looks up the integer associated with a given field name. @param value [String, Symbol] @return [Integer]

# File 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) click to toggle source

look up changes based on field name @param value [String, Symbol] @return [Change]

# File lib/card/change.rb, line 53
def find_by_field_name value
  find_by_field field_index(value)
end

Public Instance Methods

field() click to toggle source

retrieve field name @return [String]

# File lib/card/change.rb, line 66
def field
  TRACKED_FIELDS[read_attribute(:field)]
end
field=(value) click to toggle source

set field value (integer) @param value [String, Symbol]

# File lib/card/change.rb, line 60
def field= value
  write_attribute(:field, TRACKED_FIELDS.index(value.to_s))
end