has_state_machine 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/has_state_machine/state.rb +8 -0
- data/lib/has_state_machine/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 825270788dd41e2ffaee9573eea5e6bda6b63a21d9520cfd7805070feff0fac3
|
4
|
+
data.tar.gz: fd7679aafbd2aa7a21b522b99b13d7481d3b7bb8a345c4602380fdab581215d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a6251974a28867af9fd6f589f6680e231ad3e6e864e44e0f7303677e3d82ea492956c2bb48adc9c04ed56308158f13bd54ab63cdb11f6f995525adc42b0da27
|
7
|
+
data.tar.gz: 0a5db9a428f4c8f71f129c1c3133f50874f81be8933f5bc1177e0a2fb268c7ad1cd38427a2f2a398f91e721f71fdbf3ceaab094972953f3d2da4e16bb887e3d2
|
data/README.md
CHANGED
@@ -75,6 +75,10 @@ module Workflow
|
|
75
75
|
|
76
76
|
after_transition do
|
77
77
|
Rails.logger.info "Post has been archived\n"
|
78
|
+
|
79
|
+
# You can access the previous state of the object in
|
80
|
+
# after_transition callbacks as well.
|
81
|
+
Rails.logger.info "Transitioned from #{previous_state}\n"
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
@@ -75,6 +75,14 @@ module HasStateMachine
|
|
75
75
|
possible_transitions.include? desired_state
|
76
76
|
end
|
77
77
|
|
78
|
+
##
|
79
|
+
# Helper method for grabbing the previous state of the object after
|
80
|
+
# it has been transitioned to the new state. Useful in
|
81
|
+
# after_transition blocks
|
82
|
+
def previous_state
|
83
|
+
object.previous_changes[object.state_attribute]&.first
|
84
|
+
end
|
85
|
+
|
78
86
|
def state_instance(desired_state)
|
79
87
|
klass = "#{object.workflow_namespace}::#{desired_state.to_s.classify}".safe_constantize
|
80
88
|
klass&.new(object)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_state_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Hargett
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|