Module: Card::Set::All::History

Extended by:
Card::Set
Defined in:
tmpsets/set/mod005-history/all/history.rb,
tmpsets/set/mod005-history/all/history/acts.rb,
tmpsets/set/mod005-history/all/history/last.rb,
tmpsets/set/mod005-history/all/history/views.rb,
tmpsets/set/mod005-history/all/history/events.rb,
tmpsets/set/mod005-history/all/history/actions.rb,
tmpsets/set/mod005-history/all/history/revision.rb,
tmpsets/set/mod005-history/all/history/selected.rb,
tmpsets/set/mod005-history/all/history/act_listing.rb

Overview

track history (acts, actions, changes) on this card

Defined Under Namespace

Modules: ActListing, Actions, Acts, Events, Last, Revision, Selected, Views

Class Method Summary collapse

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#abstract_set?, #all_set?, #num_set_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



8
# File 'tmpsets/set/mod005-history/all/history.rb', line 8

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/history/set/all/history.rb"; end

Instance Method Details

#action_countObject



32
33
34
# File 'tmpsets/set/mod005-history/all/history.rb', line 32

def action_count
  Card::Action.where(card_id: @current_action.card_id).count
end

#changed_fieldsObject



41
42
43
# File 'tmpsets/set/mod005-history/all/history.rb', line 41

def changed_fields
  Card::Change::TRACKED_FIELDS & (changed_attribute_names_to_save | saved_changes.keys)
end

#clear_historyObject



64
65
66
67
# File 'tmpsets/set/mod005-history/all/history.rb', line 64

def clear_history
  delete_all_changes
  delete_old_actions
end

#delete_all_changesObject



73
74
75
# File 'tmpsets/set/mod005-history/all/history.rb', line 73

def delete_all_changes
  Card::Change.where(card_action_id: all_action_ids).delete_all
end

#delete_old_actionsObject



69
70
71
# File 'tmpsets/set/mod005-history/all/history.rb', line 69

def delete_old_actions
  old_actions.delete_all
end

#diff_argsObject



52
53
54
# File 'tmpsets/set/mod005-history/all/history.rb', line 52

def diff_args
  { diff_format: :text }
end

#first_change?Boolean

~~FIXME~~: optimize (no need to instantiate all actions and changes!) Nothing is instantiated here. ActiveRecord is much smarter than you think. Methods like #empty? and #size make sql queries if their receivers are not already loaded -pk

Returns:

  • (Boolean)


22
23
24
25
26
# File 'tmpsets/set/mod005-history/all/history.rb', line 22

def first_change?
  # = update or delete
  @current_action.action_type != :create && action_count == 2 &&
    create_action.card_changes.empty?
end

#first_create?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'tmpsets/set/mod005-history/all/history.rb', line 28

def first_create?
  @current_action.action_type == :create && action_count == 1
end

#has_edits?Boolean

card has account that is responsible for prior acts

Returns:

  • (Boolean)


37
38
39
# File 'tmpsets/set/mod005-history/all/history.rb', line 37

def has_edits?
  Card::Act.where(actor_id: id).where("card_id IS NOT NULL").present?
end

#history?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'tmpsets/set/mod005-history/all/history.rb', line 9

def history?
  true
end

#history_card_idsObject

all cards whose acts are considered part of this card's history



14
15
16
# File 'tmpsets/set/mod005-history/all/history.rb', line 14

def history_card_ids
  includee_ids << id
end

#includee_idsObject



45
46
47
48
49
50
# File 'tmpsets/set/mod005-history/all/history.rb', line 45

def includee_ids
  @includee_ids ||=
    Card::Reference.select(:referee_id).where(
      ref_type: "I", referer_id: id
    ).pluck("referee_id").compact.uniq
end

#make_last_action_the_initial_actionObject

Delete all changes and old actions and make the last action the create action (that way the changes for that action will be created with the first update)



58
59
60
61
62
# File 'tmpsets/set/mod005-history/all/history.rb', line 58

def make_last_action_the_initial_action
  delete_all_changes
  old_actions.delete_all
  last_action.update! action_type: :create
end

#save_content_draft(content) ⇒ Object



77
78
79
80
81
82
83
# File 'tmpsets/set/mod005-history/all/history.rb', line 77

def save_content_draft content
  super
  acts.create do |act|
    act.ar_actions.build(draft: true, card_id: id, action_type: :update)
       .card_changes.build(field: :db_content, value: content)
  end
end