Class: Card::Action

Inherits:
Cardio::Record
  • Object
show all
Extended by:
Admin
Includes:
Changes, Differ
Defined in:
lib/card/action.rb,
lib/card/action/admin.rb,
lib/card/action/differ.rb,
lib/card/action/changes.rb,
lib/card/action/action_renderer.rb

Overview

An action is a group of changes to a single card that is recorded during an act. 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 a given card, that would be recorded as one action with two changes. If there are multiple cards changed, each card would have its own action, but the whole submission would still comprise just one single act.

An Action records:

  • the card_id of the card acted upon

  • the card_act_id of the act of which the action is part

  • the action_type (create, update, or delete)

  • a boolean indicated whether the action is a draft

  • a comment (where applicable)

Defined Under Namespace

Modules: Admin, Changes, Differ Classes: ActionRenderer

Constant Summary collapse

TYPE_OPTIONS =

these are the three possible values for action_type

%i[create update delete].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Admin

delete_cardless, delete_old, make_current_state_the_initial_state

Methods included from Changes

#all_changes, #change, #changed_values, #changes, #current_changes, #previous_change, #previous_value, #value

Methods included from Differ

#cardtype_diff, #content_diff, #new_content?, #new_name?, #new_type?, #raw_view, #summary_diff_omits_content?

Class Method Details

.all_viewableObject



66
67
68
# File 'lib/card/action.rb', line 66

def all_viewable
  all_with_cards.where Query::CardQuery.viewable_sql
end

.all_with_cardsObject



62
63
64
# File 'lib/card/action.rb', line 62

def all_with_cards
  joins :ar_card
end

.cacheCard::Cache

cache object for actions

Returns:

  • (Card::Cache)


58
59
60
# File 'lib/card/action.rb', line 58

def cache
  Card::Cache[Action]
end

.fetch(id) ⇒ Action?

retrieve action from cache if available

Parameters:

Returns:



50
51
52
53
54
# File 'lib/card/action.rb', line 50

def fetch id
  cache.fetch id.to_s do
    where(id: id.to_i).take
  end
end

Instance Method Details

#action_typeSymbol

retrieve action_type (create, update, or delete)

Returns:

  • (Symbol)


96
97
98
99
100
# File 'lib/card/action.rb', line 96

def action_type
  return :draft if draft

  TYPE_OPTIONS[read_attribute(:action_type)]
end

#action_type=(value) ⇒ Integer

assign action_type (create, update, or delete)

Parameters:

  • value (Symbol)

Returns:

  • (Integer)


90
91
92
# File 'lib/card/action.rb', line 90

def action_type= value
  write_attribute :action_type, TYPE_OPTIONS.index(value)
end

#cardCard

each action is associated with on and only one card

Returns:



78
79
80
# File 'lib/card/action.rb', line 78

def card
  Card.fetch card_id, look_in_trash: true
end

#card_idObject

sometimes Object#card_id interferes with default ActiveRecord attribute def



72
73
74
# File 'lib/card/action.rb', line 72

def card_id
  _read_attribute "card_id"
end

#expireObject

remove action from action cache



83
84
85
# File 'lib/card/action.rb', line 83

def expire
  self.class.cache.delete id.to_s
end

#previous_actionObject



102
103
104
# File 'lib/card/action.rb', line 102

def previous_action
  Card::Action.where("id < ? AND card_id = ?", id, card_id).last
end

#sole?Boolean

Returns:

  • (Boolean)


106
107
108
109
# File 'lib/card/action.rb', line 106

def sole?
  all_changes.empty? &&
    (action_type == :create || Card::Action.where(card_id: card_id).count == 1)
end