flow_state 0.1.5 → 0.1.6

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd321404b1377586159f944e0216958b388ea12c6c908b451b7c91fdf2c182f7
4
- data.tar.gz: a277e49169368efd99c369a9997c05137e09a1e938e4f06d46ec91435861d18a
3
+ metadata.gz: 957aaac94425fb52e1566d1e89c8084c01f021b5fefff56a9899ee69d06ff8fc
4
+ data.tar.gz: 8b5949635034e88ed15fe31ae1c3c4e6cd6343785a823c9251e2c88911d7520a
5
5
  SHA512:
6
- metadata.gz: 6be0cf9921d7f9325b2f8b1a21a9dff8096820f1463b3a9f3dc5994f8fbf9a041aff8f14cd759401509fa160059bb8b1852e8b84d5e57466e0afabfcf79844fe
7
- data.tar.gz: 54d6ebe4873cadf6919e210daf15ede20363e197e22be3923c376a52dcc58ab3c9fef8245f71465b87a42d4743dc4f6f45f9ab8158c26f6784c8db67070cb296
6
+ metadata.gz: 8798ed03aa73c9120d27641692a0165d7a82c4e8d9b4531b74c1483ab87fb5e896fa7e323611cce81f8d120030bc5c94df79887337befdb7208dcde8190e4d09
7
+ data.tar.gz: 499e2d7f6da573ce36e95e491275d42e2846affe7d8def6c02c9db5013417fc495b639eb223bd96a789f9e92b6af4a152a0d8281038b34719fca1490e5663518
@@ -61,7 +61,7 @@ module FlowState
61
61
  validates :current_state, presence: true
62
62
  validate :validate_payload
63
63
 
64
- after_initialize { self.current_state ||= resolve_initial_state }
64
+ after_initialize :assign_initial_state, if: :new_record?
65
65
 
66
66
  def transition!(from:, to:, guard: nil, persists: nil, after_transition: nil, &block)
67
67
  setup_transition!(from, to, guard, persists, &block)
@@ -75,6 +75,10 @@ module FlowState
75
75
 
76
76
  private
77
77
 
78
+ def assign_initial_state
79
+ self.current_state ||= resolve_initial_state
80
+ end
81
+
78
82
  def setup_transition!(from, to, guard, persists, &block)
79
83
  @from_states = Array(from).map(&:to_sym)
80
84
  @to_state = to.to_sym
@@ -85,9 +89,10 @@ module FlowState
85
89
  end
86
90
 
87
91
  def perform_transition!(to, persists) # rubocop:disable Metrics/MethodLength
88
- with_lock do
89
- ensure_valid_from_state!(@from_states, to)
90
- transaction do
92
+ transaction do
93
+ save! if changed?
94
+ with_lock do
95
+ ensure_valid_from_state!(@from_states, to)
91
96
  @tr = flow_transitions.create!(
92
97
  transitioned_from: current_state,
93
98
  transitioned_to: to
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FlowState
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flow_state
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Garrett