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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a7e45d8de5f1bfdeb758a8d6b04668cceb84ef0fe41add93277237b48e0a75f
4
- data.tar.gz: 1dcb7de655710c843ccd1a8521c7760bcbcde34e0c64324744a5e2dc2a2047d7
3
+ metadata.gz: 825270788dd41e2ffaee9573eea5e6bda6b63a21d9520cfd7805070feff0fac3
4
+ data.tar.gz: fd7679aafbd2aa7a21b522b99b13d7481d3b7bb8a345c4602380fdab581215d8
5
5
  SHA512:
6
- metadata.gz: 99bc942766e3741de93c38ba9fdd06300bb70ba688853b171525517a41c7830a56b144c49b31e129f5055dc3cb2b3d11901cf72cddaa0515df0095f973fc5332
7
- data.tar.gz: 23a277ebd986ea496608e51a68a60d0696ae0366443605bc936bcce7481b0ff25ab9f66eeb004017d8dc34bbf320de837764482eb413c74acc582c649e06bcf6
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HasStateMachine
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.1
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-10-30 00:00:00.000000000 Z
12
+ date: 2020-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails