Module: Mongoid::History::Tracker

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid/history/tracker.rb

Instance Method Summary collapse

Instance Method Details

#affectedObject



79
80
81
82
# File 'lib/mongoid/history/tracker.rb', line 79

def affected
  @affected ||= (modified.keys | original.keys).inject({}){ |h,k| h[k] =
    trackable ? trackable.attributes[k] : modified[k]; h}
end

#redo!(modifier) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/mongoid/history/tracker.rb', line 37

def redo!(modifier)
  if action.to_sym == :destroy
    re_destroy
  elsif action.to_sym == :create
    re_create
  else
    trackable.update_attributes!(redo_attr(modifier))
  end
end

#redo_attr(modifier) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/mongoid/history/tracker.rb', line 55

def redo_attr(modifier)
  redo_hash = affected.easy_unmerge(original)
  redo_hash.easy_merge!(modified)
  modifier_field = trackable.history_trackable_options[:modifier_field]
  redo_hash[modifier_field] = modifier
  redo_hash
end

#trackableObject



67
68
69
# File 'lib/mongoid/history/tracker.rb', line 67

def trackable
  @trackable ||= trackable_parents_and_trackable.last
end

#trackable_parentObject



75
76
77
# File 'lib/mongoid/history/tracker.rb', line 75

def trackable_parent
  @trackable_parent ||= trackable_parents_and_trackable[-2]
end

#trackable_parentsObject



71
72
73
# File 'lib/mongoid/history/tracker.rb', line 71

def trackable_parents
  @trackable_parents ||= trackable_parents_and_trackable[0, -1]
end

#trackable_rootObject



63
64
65
# File 'lib/mongoid/history/tracker.rb', line 63

def trackable_root
  @trackable_root ||= trackable_parents_and_trackable.first
end

#undo!(modifier) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/mongoid/history/tracker.rb', line 27

def undo!(modifier)
  if action.to_sym == :destroy
    re_create
  elsif action.to_sym == :create
    re_destroy
  else
    trackable.update_attributes!(undo_attr(modifier))
  end
end

#undo_attr(modifier) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/mongoid/history/tracker.rb', line 47

def undo_attr(modifier)
  undo_hash = affected.easy_unmerge(modified)
  undo_hash.easy_merge!(original)
  modifier_field = trackable.history_trackable_options[:modifier_field]
  undo_hash[modifier_field] = modifier
  undo_hash
end