state_machine-audit_trail 0.0.1 → 0.0.2
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.
- data/README.rdoc +5 -5
- data/lib/state_machine/audit_trail.rb +4 -5
- data/lib/state_machine/audit_trail/active_record.rb +2 -2
- data/lib/state_machine/audit_trail/backend.rb +7 -0
- data/lib/state_machine/audit_trail/{transition_logging.rb → transition_auditing.rb} +3 -3
- data/spec/spec_helper.rb +3 -3
- data/state_machine-audit_trail.gemspec +3 -3
- metadata +5 -5
- data/lib/state_machine/audit_trail/base.rb +0 -5
data/README.rdoc
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
= StateMachine audit trail
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This plugin for the state machine gem (see https://github.com/pluginaweek/state_machine) adds support for keeping an audit trail for any state machine. Having an audit trail gives you a complete history of the state changes in your model. This history allows you to investigate incidents or perform analytics, like: "How long does it take on average to go from state a to state b?", or "What percentage of cases goes from state a to b via state c?"
|
|
4
4
|
|
|
5
5
|
Note: while the state_machine gem integrates with multiple ORMs, this plugin currently only has an ActiveRecord backend. It should be easy to add support for other ActiveModel-based ORMs though.
|
|
6
6
|
|
|
@@ -16,22 +16,22 @@ Create a model/table that holds the audit trail. The table needs to have a forei
|
|
|
16
16
|
|
|
17
17
|
For a model called "Model", and a state attribute "state", this will generate the ModelStateTransition model and an accompanying migration.
|
|
18
18
|
|
|
19
|
-
Next, tell your state machine you want to
|
|
19
|
+
Next, tell your state machine you want to store an audit trail:
|
|
20
20
|
|
|
21
21
|
class Model < ActiveRecord::Base
|
|
22
22
|
state_machine :state, :initial => :start do
|
|
23
|
-
|
|
23
|
+
store_audit_trail
|
|
24
24
|
...
|
|
25
25
|
|
|
26
26
|
If your audit trail model does not use the default naming scheme, provide it using the <tt>:to</tt> option:
|
|
27
27
|
|
|
28
28
|
class Model < ActiveRecord::Base
|
|
29
29
|
state_machine :state, :initial => :start do
|
|
30
|
-
|
|
30
|
+
store_audit_trail :to => 'ModelAuditTrail'
|
|
31
31
|
...
|
|
32
32
|
|
|
33
33
|
That's it! The plugin will register an <tt>after_transition</tt> callback that is used to log all transitions. It will also log the initial state if there is one.
|
|
34
34
|
|
|
35
35
|
== About
|
|
36
36
|
|
|
37
|
-
This plugin is written by Jesse Storimer and Willem van Bergen for Shopify. It is released under the MIT license (see LICENSE)
|
|
37
|
+
This plugin is written by Jesse Storimer and Willem van Bergen for Shopify. It is released under the MIT license (see LICENSE)
|
|
@@ -2,10 +2,10 @@ require 'state_machine'
|
|
|
2
2
|
|
|
3
3
|
module StateMachine::AuditTrail
|
|
4
4
|
|
|
5
|
-
VERSION = "0.0.
|
|
5
|
+
VERSION = "0.0.2"
|
|
6
6
|
|
|
7
7
|
def self.setup
|
|
8
|
-
StateMachine::Machine.send(:include, StateMachine::AuditTrail::
|
|
8
|
+
StateMachine::Machine.send(:include, StateMachine::AuditTrail::TransitionAuditing)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def self.create(transition_class)
|
|
@@ -14,8 +14,7 @@ module StateMachine::AuditTrail
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
require 'state_machine/audit_trail/
|
|
18
|
-
require 'state_machine/audit_trail/
|
|
19
|
-
require 'state_machine/audit_trail/active_record'
|
|
17
|
+
require 'state_machine/audit_trail/transition_auditing'
|
|
18
|
+
require 'state_machine/audit_trail/backend'
|
|
20
19
|
require 'state_machine/audit_trail/railtie' if defined?(::Rails)
|
|
21
20
|
StateMachine::AuditTrail.setup
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
class StateMachine::AuditTrail::ActiveRecord < StateMachine::AuditTrail::
|
|
1
|
+
class StateMachine::AuditTrail::ActiveRecord < StateMachine::AuditTrail::Backend
|
|
2
2
|
def log(object, event, from, to, timestamp = Time.now)
|
|
3
3
|
# Let ActiveRecord manage the timestamp for us so it does the
|
|
4
|
-
# right thing
|
|
4
|
+
# right thing with regards to timezones.
|
|
5
5
|
transition_class.create(foreign_key_field(object) => object.id, :event => event, :from => from, :to => to)
|
|
6
6
|
end
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
module StateMachine::AuditTrail::
|
|
1
|
+
module StateMachine::AuditTrail::TransitionAuditing
|
|
2
2
|
attr_accessor :transition_class_name
|
|
3
3
|
|
|
4
|
-
def
|
|
4
|
+
def store_audit_trail(options = {})
|
|
5
5
|
state_machine = self
|
|
6
6
|
state_machine.transition_class_name = (options[:to] || default_transition_class_name).to_s
|
|
7
7
|
|
|
@@ -17,7 +17,7 @@ module StateMachine::AuditTrail::TransitionLogging
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def audit_trail
|
|
20
|
-
@
|
|
20
|
+
@transition_auditor ||= StateMachine::AuditTrail.create(transition_class)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
private
|
data/spec/spec_helper.rb
CHANGED
|
@@ -53,7 +53,7 @@ end
|
|
|
53
53
|
class TestModel < ActiveRecord::Base
|
|
54
54
|
|
|
55
55
|
state_machine :state, :initial => :waiting do # log initial state?
|
|
56
|
-
|
|
56
|
+
store_audit_trail
|
|
57
57
|
|
|
58
58
|
event :start do
|
|
59
59
|
transition [:waiting, :stopped] => :started
|
|
@@ -68,7 +68,7 @@ end
|
|
|
68
68
|
class TestModelWithMultipleStateMachines < ActiveRecord::Base
|
|
69
69
|
|
|
70
70
|
state_machine :first, :initial => :beginning do
|
|
71
|
-
|
|
71
|
+
store_audit_trail
|
|
72
72
|
|
|
73
73
|
event :begin_first do
|
|
74
74
|
transition :beginning => :end
|
|
@@ -76,7 +76,7 @@ class TestModelWithMultipleStateMachines < ActiveRecord::Base
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
state_machine :second do
|
|
79
|
-
|
|
79
|
+
store_audit_trail
|
|
80
80
|
|
|
81
81
|
event :begin_second do
|
|
82
82
|
transition nil => :beginning
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
Gem::Specification.new do |s|
|
|
3
3
|
s.name = "state_machine-audit_trail"
|
|
4
|
-
s.version = "0.0.
|
|
4
|
+
s.version = "0.0.2"
|
|
5
5
|
s.platform = Gem::Platform::RUBY
|
|
6
6
|
s.authors = ["Willem van Bergen", "Jesse Storimer"]
|
|
7
|
-
s.email = ["willem@shopify.com", "jesse
|
|
7
|
+
s.email = ["willem@shopify.com", "jesse@shopify.com"]
|
|
8
8
|
s.homepage = "https://github.com/wvanbergen/state_machine-audit_trail"
|
|
9
9
|
s.summary = %q{Log transitions on a state machine to support auditing and business process analytics.}
|
|
10
10
|
s.description = %q{Log transitions on a state machine to support auditing and business process analytics.}
|
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.add_development_dependency('activerecord', '~> 3')
|
|
19
19
|
s.add_development_dependency('sqlite3')
|
|
20
20
|
|
|
21
|
-
s.files = %w(.gitignore Gemfile LICENSE README.rdoc Rakefile lib/state_machine-audit_trail.rb lib/state_machine/audit_trail.rb lib/state_machine/audit_trail/active_record.rb lib/state_machine/audit_trail/
|
|
21
|
+
s.files = %w(.gitignore Gemfile LICENSE README.rdoc Rakefile lib/state_machine-audit_trail.rb lib/state_machine/audit_trail.rb lib/state_machine/audit_trail/active_record.rb lib/state_machine/audit_trail/backend.rb lib/state_machine/audit_trail/railtie.rb lib/state_machine/audit_trail/transition_auditing.rb lib/state_machine/audit_trail_generator.rb spec/spec_helper.rb spec/state_machine/audit_trail_spec.rb state_machine-audit_trail.gemspec tasks/github_gem.rb)
|
|
22
22
|
s.test_files = %w(spec/state_machine/audit_trail_spec.rb)
|
|
23
23
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 0.0.
|
|
8
|
+
- 2
|
|
9
|
+
version: 0.0.2
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Willem van Bergen
|
|
@@ -86,7 +86,7 @@ dependencies:
|
|
|
86
86
|
description: Log transitions on a state machine to support auditing and business process analytics.
|
|
87
87
|
email:
|
|
88
88
|
- willem@shopify.com
|
|
89
|
-
- jesse
|
|
89
|
+
- jesse@shopify.com
|
|
90
90
|
executables: []
|
|
91
91
|
|
|
92
92
|
extensions: []
|
|
@@ -102,9 +102,9 @@ files:
|
|
|
102
102
|
- lib/state_machine-audit_trail.rb
|
|
103
103
|
- lib/state_machine/audit_trail.rb
|
|
104
104
|
- lib/state_machine/audit_trail/active_record.rb
|
|
105
|
-
- lib/state_machine/audit_trail/
|
|
105
|
+
- lib/state_machine/audit_trail/backend.rb
|
|
106
106
|
- lib/state_machine/audit_trail/railtie.rb
|
|
107
|
-
- lib/state_machine/audit_trail/
|
|
107
|
+
- lib/state_machine/audit_trail/transition_auditing.rb
|
|
108
108
|
- lib/state_machine/audit_trail_generator.rb
|
|
109
109
|
- spec/spec_helper.rb
|
|
110
110
|
- spec/state_machine/audit_trail_spec.rb
|