mongoid-history 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -38,6 +38,7 @@ module Mongoid::History
38
38
  extend SingletonMethods
39
39
 
40
40
  delegate :history_trackable_options, :to => 'self.class'
41
+ delegate :track_history?, :to => 'self.class'
41
42
 
42
43
  before_update :track_update
43
44
  before_create :track_create if options[:track_create]
@@ -47,8 +48,18 @@ module Mongoid::History
47
48
  Mongoid::History.trackable_classes << self
48
49
  Mongoid::History.trackable_class_options ||= {}
49
50
  Mongoid::History.trackable_class_options[model_name] = options
51
+ Thread.current[:mongoid_history_trackable_enabled] = true
50
52
  end
51
53
 
54
+ def track_history?
55
+ !!Thread.current[:mongoid_history_trackable_enabled]
56
+ end
57
+
58
+ def disable_tracking(&block)
59
+ Thread.current[:mongoid_history_trackable_enabled] = false
60
+ yield
61
+ Thread.current[:mongoid_history_trackable_enabled] = true
62
+ end
52
63
  end
53
64
 
54
65
  module InstanceMethods
@@ -58,7 +69,7 @@ module Mongoid::History
58
69
 
59
70
  private
60
71
  def should_track_update?
61
- !modified_attributes_for_update.blank?
72
+ track_history? && !modified_attributes_for_update.blank?
62
73
  end
63
74
 
64
75
  def triverse_association_chain(node=self)
@@ -113,6 +124,7 @@ module Mongoid::History
113
124
  end
114
125
 
115
126
  def track_create
127
+ return unless track_history?
116
128
  current_version = (self.send(history_trackable_options[:version_field]) || 0 ) + 1
117
129
  self.send("#{history_trackable_options[:version_field]}=", current_version)
118
130
  Mongoid::History.tracker_class.create!(history_tracker_attributes.merge(:version => current_version))
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid-history}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Qian"]
12
- s.date = %q{2011-03-06}
12
+ s.date = %q{2011-03-07}
13
13
  s.description = %q{In frustration of Mongoid::Versioning, I created this plugin for tracking historical changes for any document, including embedded ones. It achieves this by storing all history tracks in a single collection that you define. (See Usage for more details) Embedded documents are referenced by storing an association path, which is an array of document_name and document_id fields starting from the top most parent document and down to the embedded document that should track history.
14
14
 
15
15
  This plugin implements multi-user undo, which allows users to undo any history change in any order. Undoing a document also creates a new history track. This is great for auditing and preventing vandalism, but it is probably not suitable for use cases such as a wiki.}
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid-history
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Aaron Qian
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-06 00:00:00 -08:00
13
+ date: 2011-03-07 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - ">="
169
169
  - !ruby/object:Gem::Version
170
- hash: -4589189191115367559
170
+ hash: -4485611789112804696
171
171
  segments:
172
172
  - 0
173
173
  version: "0"