Module: Mongoid::History::Trackable::MyInstanceMethods
- Defined in:
- lib/mongoid/history/trackable.rb
Instance Method Summary collapse
- #_create_relation(name, value) ⇒ Object
- #_get_relation(name) ⇒ Object
- #history_tracks ⇒ Object
- #redo!(modifier = nil, options_or_version = nil) ⇒ Object
-
#undo(modifier = nil, options_or_version = nil) ⇒ Object
undo :from => 1, :to => 5 undo 4 undo :last => 10.
-
#undo!(modifier = nil, options_or_version = nil) ⇒ Object
undo! :from => 1, :to => 5 undo! 4 undo! :last => 10.
Instance Method Details
#_create_relation(name, value) ⇒ Object
136 137 138 |
# File 'lib/mongoid/history/trackable.rb', line 136 def _create_relation(name, value) send("create_#{self.class.relation_alias(name)}!", value) end |
#_get_relation(name) ⇒ Object
132 133 134 |
# File 'lib/mongoid/history/trackable.rb', line 132 def _get_relation(name) send(self.class.relation_alias(name)) end |
#history_tracks ⇒ Object
85 86 87 88 89 90 |
# File 'lib/mongoid/history/trackable.rb', line 85 def history_tracks @history_tracks ||= self.class.tracker_class.where( scope: , association_chain: association_hash ).asc(:version) end |
#redo!(modifier = nil, options_or_version = nil) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/mongoid/history/trackable.rb', line 117 def redo!(modifier = nil, = nil) versions = get_versions_criteria().to_a versions.sort! { |v1, v2| v1.version <=> v2.version } versions.each do |v| redo_attr = v.redo_attr(modifier) if Mongoid::Compatibility::Version.mongoid3? assign_attributes(redo_attr, without_protection: true) save! else update_attributes!(redo_attr) end end end |
#undo(modifier = nil, options_or_version = nil) ⇒ Object
undo :from => 1, :to => 5
undo 4
undo :last => 10
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mongoid/history/trackable.rb', line 95 def undo(modifier = nil, = nil) versions = get_versions_criteria().to_a versions.sort! { |v1, v2| v2.version <=> v1.version } versions.each do |v| undo_attr = v.undo_attr(modifier) if Mongoid::Compatibility::Version.mongoid3? # update_attributes! not bypassing rails 3 protected attributes assign_attributes(undo_attr, without_protection: true) else # assign_attributes with 'without_protection' option does not work with rails 4/mongoid 4 self.attributes = undo_attr end end end |
#undo!(modifier = nil, options_or_version = nil) ⇒ Object
undo! :from => 1, :to => 5
undo! 4
undo! :last => 10
112 113 114 115 |
# File 'lib/mongoid/history/trackable.rb', line 112 def undo!(modifier = nil, = nil) undo(modifier, ) save! end |