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

Extended by:
Card::Set
Defined in:
platypus/tmp/set/gem-defaults/mod015-history/all/history.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/acts.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/last.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/views.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/events.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/export.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/actions.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/revision.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/selected.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/act_listing.rb

Overview

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

Defined Under Namespace

Modules: ActListing, Actions, Acts, Events, Export, 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

Methods included from I18nScope

#mod_name, #scope

Methods included from Registrar

#extended, #finalize_load, #process_base_modules, #register_set

Methods included from Helpers

#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name

Methods included from Card::Set::AdvancedApi

#assign_type, #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 Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



8
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 8

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

Instance Method Details

#action_countObject



49
50
51
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 49

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

#changed_fieldsObject



58
59
60
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 58

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

#clear_historyObject



82
83
84
85
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 82

def clear_history
  delete_all_changes
  delete_old_actions
end

#delete_all_changesObject



91
92
93
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 91

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

#delete_old_actionsObject



87
88
89
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 87

def delete_old_actions
  old_actions.delete_all
end

#diff_argsObject



70
71
72
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 70

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)


39
40
41
42
43
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 39

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)


45
46
47
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 45

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)


54
55
56
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 54

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 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 9

def history?
  true
end

#history_ancestor_ids(recursion_level = 0) ⇒ Object



27
28
29
30
31
32
33
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 27

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

  ids = history_parent_ids +
        history_parent_ids.map { |id| id.card&.history_ancestor_ids(recursion_level + 1) }
  ids.flatten.compact
end

#history_card_idsObject

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



18
19
20
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 18

def history_card_ids
  nestee_ids << id
end

#history_parent_idsObject

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



23
24
25
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 23

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)



76
77
78
79
80
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 76

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

#nestee_idsObject



62
63
64
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 62

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

#nester_idsObject



66
67
68
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 66

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

#no_history?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 13

def no_history?
  !history?
end

#save_content_draft(content) ⇒ Object



95
96
97
98
99
100
101
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 95

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