state_machine-audit_trail 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDliMWUwOGMyMzhhNzgxODQ3YjU0NWNjNDkwNjI5Nzk1NWVkOTc0OA==
5
- data.tar.gz: !binary |-
6
- YTFiYmZjMjY3YjhhNjJhYzNlMjhlZmQyYWVjZGY0YjZjMGExOTgyZg==
2
+ SHA1:
3
+ metadata.gz: 1d5ee2c13387ab1270a616717c204ceddd3e0cff
4
+ data.tar.gz: 1134c034ff9a27b4f2954cfd27ec5950fc364c7f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZjM3MDNlNTFmNWNiNTdmYWU3ZDMwZjc5OTJkZGI4M2Y5MDZmYmNmY2NiMDNj
10
- MjQ1YWRhYmViYzk2NzZiNTRkZTQxNzNlNmZiOGI4M2NhMWFjMGFmMmQ2NzRm
11
- NTQyMGVjZTBmNDI2MmNhYjhhYTFjMTVmY2UxZjhjZmI3NTNkMDg=
12
- data.tar.gz: !binary |-
13
- MzY2NzM5M2I4ZjBiNTA4NzE5YmFlYWE1MTliOTUyMjc0NTBhNjM4MmI2NDJj
14
- YjljN2NhYmEzZjA2NDgzM2NmNWE0MzNiMzgwNjVmMmE2NjJhMDkzNGJhMDcw
15
- Y2IxOWJiOTFhMWE2NzFhNWE0MGY4MDU1OTM2Mzg3OTcyMDZkNTI=
6
+ metadata.gz: 220617450fd6439a7decddafc0dffc4ca2a1fd3ef0a1cb10d1d60400e710bc318c2153e64cd06049b5e38e39ebbfc5955507c61ce96bfb75875e17025b43bd74
7
+ data.tar.gz: 2e8c5702276277406e7031be5df9e538fd502fec261dd7941ff10145cfdf2179ccb04756a55c645043a27c541ad7e5b11f8f5a2a9dccd962830759b9f42a6cae
data/README.rdoc CHANGED
@@ -46,6 +46,29 @@ If you would like to store additional messages in the audit trail, you can do so
46
46
  or
47
47
  store_audit_trail :context_to_log => [:field1, :field2] # Will grab the results of the field1 and field2 methods on the model and store them in fields called field1 and field2 on the audit trail model
48
48
 
49
+ === Store virtual attributes
50
+
51
+ Sometimes it can be useful to store dynamically computed information.
52
+
53
+ In these situations it's just a matter of defining a new column on table <tt>DeploymentStateTransitions</tt> and configure <tt>context_to_log</tt>.
54
+
55
+ i.e.
56
+
57
+ class Model < ActiveRecord::Base
58
+ state_machine :state, :initial => :start do
59
+ store_audit_trail :context_to_log => :version
60
+ ...
61
+
62
+ def version
63
+ # Dynamically computed field e.g., based on other models
64
+ ...
65
+
66
+ class AddVersionToDeploymentStateTransitions < ActiveRecord::Migration
67
+ def change
68
+ add_column :deployment_state_transitions, :version, :string
69
+ ...
70
+
71
+
49
72
  == About
50
73
 
51
74
  This plugin is written by Jesse Storimer and Willem van Bergen for Shopify. Mongoid support was contributed by Siddharth (https://github.com/svs). It is released under the MIT license (see LICENSE).
@@ -12,22 +12,28 @@ module StateMachine::AuditTrail::TransitionAuditing
12
12
  def store_audit_trail(options = {})
13
13
  state_machine = self
14
14
  state_machine.transition_class_name = (options[:to] || default_transition_class_name).to_s
15
+ state_machine.setup_backend(options[:context_to_log])
16
+
15
17
  state_machine.after_transition do |object, transition|
16
- state_machine.audit_trail(options[:context_to_log]).log(object, transition.event, transition.from, transition.to)
18
+ state_machine.backend.log(object, transition.event, transition.from, transition.to)
17
19
  end
18
20
 
19
21
  unless state_machine.action == nil
20
22
  state_machine.owner_class.after_create do |object|
21
23
  if !object.send(state_machine.attribute).nil?
22
- state_machine.audit_trail(options[:context_to_log]).log(object, nil, nil, object.send(state_machine.attribute))
24
+ state_machine.backend.log(object, nil, nil, object.send(state_machine.attribute))
23
25
  end
24
26
  end
25
27
  end
26
28
  end
27
29
 
30
+ def setup_backend(context_to_log = nil)
31
+ @backend = StateMachine::AuditTrail::Backend.create_for_transition_class(transition_class, self.owner_class, context_to_log)
32
+ end
33
+
28
34
  # Public returns an instance of the class which does the actual audit trail logging
29
- def audit_trail(context_to_log = nil)
30
- @transition_auditor ||= StateMachine::AuditTrail::Backend.create_for_transition_class(transition_class, self.owner_class, context_to_log)
35
+ def backend
36
+ @backend
31
37
  end
32
38
 
33
39
  private
@@ -1,5 +1,5 @@
1
1
  module StateMachine
2
2
  module AuditTrail
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
@@ -153,6 +153,10 @@ class ActiveRecordTestModelWithMultipleStateMachines < ActiveRecord::Base
153
153
  end
154
154
 
155
155
  module SomeNamespace
156
+ class ActiveRecordTestModelStateTransition < ActiveRecord::Base
157
+ belongs_to :test_model
158
+ end
159
+
156
160
  class ActiveRecordTestModel < ActiveRecord::Base
157
161
 
158
162
  state_machine :state, :initial => :waiting do # log initial state?
@@ -169,13 +173,6 @@ module SomeNamespace
169
173
  end
170
174
  end
171
175
 
172
- module SomeNamespace
173
- class ActiveRecordTestModelStateTransition < ActiveRecord::Base
174
- belongs_to :test_model
175
- end
176
- end
177
-
178
-
179
176
  def create_transition_table(owner_class, state, add_context = false)
180
177
  class_name = "#{owner_class.name}#{state.to_s.camelize}Transition"
181
178
  ActiveRecord::Base.connection.create_table(class_name.tableize) do |t|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machine-audit_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-27 00:00:00.000000000 Z
12
+ date: 2014-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: state_machine
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ! '>='
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
@@ -71,14 +71,14 @@ dependencies:
71
71
  name: sqlite3
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ! '>='
74
+ - - '>='
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ! '>='
81
+ - - '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
@@ -99,14 +99,14 @@ dependencies:
99
99
  name: bson_ext
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ! '>='
102
+ - - '>='
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ! '>='
109
+ - - '>='
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  description: Log transitions on a state machine to support auditing and business process
@@ -151,17 +151,17 @@ require_paths:
151
151
  - lib
152
152
  required_ruby_version: !ruby/object:Gem::Requirement
153
153
  requirements:
154
- - - ! '>='
154
+ - - '>='
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  requirements:
159
- - - ! '>='
159
+ - - '>='
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
163
  rubyforge_project: state_machine
164
- rubygems_version: 2.1.4
164
+ rubygems_version: 2.0.3
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: Log transitions on a state machine to support auditing and business process