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

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

Overview

Set: All cards (History)

Defined Under Namespace

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

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

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

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #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



7
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 7

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

Instance Method Details

#action_countObject



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

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

#changed_fieldsObject



61
62
63
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 61

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

#clear_historyObject



85
86
87
88
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 85

def clear_history
  delete_all_changes
  delete_old_actions
end

#delete_all_changesObject



94
95
96
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 94

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

#delete_old_actionsObject



90
91
92
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 90

def delete_old_actions
  old_actions.delete_all
end

#diff_argsObject



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

def diff_args
  { diff_format: :text }
end

#event: update_ancestor_timestampsObject



8
9
10
11
12
13
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 8

event :update_ancestor_timestamps, :integrate do
  ids = history_ancestor_ids
  return unless ids.present?
  Card.where(id: ids).update_all(updater_id: Auth.current_id, updated_at: Time.now)
  ids.map { |anc_id| Card.expire anc_id.cardname }
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)


42
43
44
45
46
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 42

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)


48
49
50
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 48

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)


57
58
59
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 57

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

#history?Boolean

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

Returns:

  • (Boolean)


16
17
18
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 16

def history?
  true
end

#history_ancestor_ids(recursion_level = 0) ⇒ Object



30
31
32
33
34
35
36
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 30

def history_ancestor_ids recursion_level=0
  return [] if recursion_level > 5

  ids = history_parent_ids +
    history_parent_ids.map { |id| Card[id].history_ancestor_ids(recursion_level + 1) }
  ids.flatten
end

#history_card_idsObject

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



21
22
23
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 21

def history_card_ids
  nestee_ids << id
end

#history_parent_idsObject

all cards who are considered updated if this card’s was updated



26
27
28
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 26

def history_parent_ids
  nester_ids
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)



79
80
81
82
83
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 79

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

#nestee_idsObject



65
66
67
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 65

def nestee_ids
  requiring_id { @nestee_ids ||= nesting_ids(:referee_id, :referer_id) }
end

#nester_idsObject



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

def nester_ids
  requiring_id { @nester_ids ||= nesting_ids(:referer_id, :referee_id) }
end

#save_content_draft(content) ⇒ Object



98
99
100
101
102
103
104
# File 'card/tmpsets/set/mod013-card-mod-history/all/history.rb', line 98

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