Class: Card::Act

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
mod/01_history/lib/card/act.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete_actionlessObject



15
16
17
18
19
20
21
22
# File 'mod/01_history/lib/card/act.rb', line 15

def delete_actionless
  joins(
    'LEFT JOIN card_actions '\
    'ON card_acts.id = card_actions.card_act_id'
  ).where(
    'card_actions.id is null'
  ).delete_all
end

.find_all_with_actions_on(card_ids, args = {}) ⇒ Object



24
25
26
27
28
29
# File 'mod/01_history/lib/card/act.rb', line 24

def find_all_with_actions_on card_ids, args={}
  sql = 'card_actions.card_id IN (:card_ids) AND ( (draft is not true) '
  sql << (args[:with_drafts] ? 'OR actor_id = :current_user_id)' : ')')
  vars = { card_ids: card_ids, current_user_id: Card::Auth.current_id }
  joins(:actions).where(sql, vars).uniq.order(:id).reverse_order
end

Instance Method Details

#action_on(card_id) ⇒ Object



36
37
38
# File 'mod/01_history/lib/card/act.rb', line 36

def action_on card_id
  actions.where("card_id = #{card_id} and draft is not true").first
end

#elapsed_timeObject



44
45
46
# File 'mod/01_history/lib/card/act.rb', line 44

def elapsed_time
  DateTime.new(acted_at).distance_of_time_in_words_to_now
end

#main_actionObject



40
41
42
# File 'mod/01_history/lib/card/act.rb', line 40

def main_action
  action_on(card_id) || actions.first
end

#relevant_actions_for(card) ⇒ Object



55
56
57
58
59
60
# File 'mod/01_history/lib/card/act.rb', line 55

def relevant_actions_for card
  actions.select do |action|
    card.included_card_ids.include?(action.card_id) ||
      (card.id == action.card_id)
  end
end

#relevant_drafts_for(card) ⇒ Object



48
49
50
51
52
53
# File 'mod/01_history/lib/card/act.rb', line 48

def relevant_drafts_for card
  drafts.select do |action|
    card.included_card_ids.include?(action.card_id) ||
      (card.id == action.card_id)
  end
end

#set_actorObject



32
33
34
# File 'mod/01_history/lib/card/act.rb', line 32

def set_actor
  self.actor_id ||= Auth.current_id
end