state_machines 0.20.0 → 0.30.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +124 -13
  3. data/lib/state_machines/branch.rb +12 -13
  4. data/lib/state_machines/callback.rb +11 -12
  5. data/lib/state_machines/core.rb +0 -1
  6. data/lib/state_machines/error.rb +5 -4
  7. data/lib/state_machines/eval_helpers.rb +83 -45
  8. data/lib/state_machines/event.rb +23 -26
  9. data/lib/state_machines/event_collection.rb +4 -5
  10. data/lib/state_machines/extensions.rb +5 -5
  11. data/lib/state_machines/helper_module.rb +1 -1
  12. data/lib/state_machines/integrations/base.rb +1 -1
  13. data/lib/state_machines/integrations.rb +11 -14
  14. data/lib/state_machines/machine/action_hooks.rb +53 -0
  15. data/lib/state_machines/machine/callbacks.rb +59 -0
  16. data/lib/state_machines/machine/class_methods.rb +25 -11
  17. data/lib/state_machines/machine/configuration.rb +124 -0
  18. data/lib/state_machines/machine/event_methods.rb +59 -0
  19. data/lib/state_machines/machine/helper_generators.rb +125 -0
  20. data/lib/state_machines/machine/integration.rb +70 -0
  21. data/lib/state_machines/machine/parsing.rb +77 -0
  22. data/lib/state_machines/machine/rendering.rb +17 -0
  23. data/lib/state_machines/machine/scoping.rb +44 -0
  24. data/lib/state_machines/machine/state_methods.rb +101 -0
  25. data/lib/state_machines/machine/utilities.rb +85 -0
  26. data/lib/state_machines/machine/validation.rb +39 -0
  27. data/lib/state_machines/machine.rb +73 -617
  28. data/lib/state_machines/machine_collection.rb +18 -14
  29. data/lib/state_machines/macro_methods.rb +2 -2
  30. data/lib/state_machines/matcher.rb +6 -6
  31. data/lib/state_machines/matcher_helpers.rb +1 -1
  32. data/lib/state_machines/node_collection.rb +18 -17
  33. data/lib/state_machines/path.rb +2 -4
  34. data/lib/state_machines/path_collection.rb +2 -3
  35. data/lib/state_machines/state.rb +6 -5
  36. data/lib/state_machines/state_collection.rb +3 -3
  37. data/lib/state_machines/state_context.rb +6 -7
  38. data/lib/state_machines/stdio_renderer.rb +16 -16
  39. data/lib/state_machines/syntax_validator.rb +57 -0
  40. data/lib/state_machines/test_helper.rb +290 -27
  41. data/lib/state_machines/transition.rb +43 -41
  42. data/lib/state_machines/transition_collection.rb +22 -25
  43. data/lib/state_machines/version.rb +1 -1
  44. metadata +23 -9
@@ -5,7 +5,6 @@ require_relative 'options_validator'
5
5
  module StateMachines
6
6
  # Represents a collection of transitions in a state machine
7
7
  class TransitionCollection < Array
8
-
9
8
  # Whether to skip running the action for each transition's machine
10
9
  attr_reader :skip_actions
11
10
 
@@ -30,10 +29,10 @@ module StateMachines
30
29
  reject! { |transition| !transition }
31
30
 
32
31
  attributes = map { |transition| transition.attribute }.uniq
33
- fail ArgumentError, 'Cannot perform multiple transitions in parallel for the same state machine attribute' if attributes.length != length
32
+ raise ArgumentError, 'Cannot perform multiple transitions in parallel for the same state machine attribute' if attributes.length != length
34
33
 
35
34
  StateMachines::OptionsValidator.assert_valid_keys!(options, :actions, :after, :use_transactions)
36
- options = {actions: true, after: true, use_transactions: true}.merge(options)
35
+ options = { actions: true, after: true, use_transactions: true }.merge(options)
37
36
  @skip_actions = !options[:actions]
38
37
  @skip_after = !options[:after]
39
38
  @use_transactions = options[:use_transactions]
@@ -76,11 +75,11 @@ module StateMachines
76
75
  end
77
76
  end
78
77
 
79
- protected
78
+ protected
80
79
 
81
- attr_reader :results #:nodoc:
80
+ attr_reader :results # :nodoc:
82
81
 
83
- private
82
+ private
84
83
 
85
84
  # Is this a valid set of transitions? If the collection was creating with
86
85
  # any +false+ values for transitions, then the the collection will be
@@ -131,7 +130,7 @@ module StateMachines
131
130
  if transition = self[index]
132
131
  throw :halt unless transition.run_callbacks(after: !skip_after) do
133
132
  run_callbacks(index + 1, &block)
134
- {result: results[transition.action], success: success?}
133
+ { result: results[transition.action], success: success? }
135
134
  end
136
135
  else
137
136
  persist
@@ -152,13 +151,13 @@ module StateMachines
152
151
  def run_actions
153
152
  catch_exceptions do
154
153
  @success = if block_given?
155
- result = yield
156
- actions.each { |action| results[action] = result }
157
- !!result
158
- else
159
- actions.compact.each { |action| !skip_actions && (results[action] = object.send(action)) }
160
- results.values.all?
161
- end
154
+ result = yield
155
+ actions.each { |action| results[action] = result }
156
+ !!result
157
+ else
158
+ actions.compact.each { |action| !skip_actions && (results[action] = object.send(action)) }
159
+ results.values.all?
160
+ end
162
161
  end
163
162
  end
164
163
 
@@ -171,12 +170,10 @@ module StateMachines
171
170
  # occur will automatically result in the transition rolling back any changes
172
171
  # that were made to the object involved.
173
172
  def catch_exceptions
174
- begin
175
- yield
176
- rescue
177
- rollback
178
- raise
179
- end
173
+ yield
174
+ rescue StandardError
175
+ rollback
176
+ raise
180
177
  end
181
178
 
182
179
  # Runs a block within a transaction for the object being transitioned. If
@@ -196,11 +193,11 @@ module StateMachines
196
193
  # Represents a collection of transitions that were generated from attribute-
197
194
  # based events
198
195
  class AttributeTransitionCollection < TransitionCollection
199
- def initialize(transitions = [], options = {}) #:nodoc:
200
- super(transitions, {use_transactions: false, actions: false}.merge(options))
196
+ def initialize(transitions = [], options = {}) # :nodoc:
197
+ super(transitions, { use_transactions: false, actions: false }.merge(options))
201
198
  end
202
199
 
203
- private
200
+ private
204
201
 
205
202
  # Hooks into running transition callbacks so that event / event transition
206
203
  # attributes can be properly updated
@@ -216,9 +213,9 @@ module StateMachines
216
213
  # Rollback only if exceptions occur during before callbacks
217
214
  begin
218
215
  super
219
- rescue
216
+ rescue StandardError
220
217
  rollback unless @before_run
221
- @success = nil # mimics ActiveRecord.save behavior on rollback
218
+ @success = nil # mimics ActiveRecord.save behavior on rollback
222
219
  raise
223
220
  end
224
221
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StateMachines
4
- VERSION = '0.20.0'
4
+ VERSION = '0.30.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.7.6
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '5.4'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '5.4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '5.4'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '5.4'
54
+ version: '0'
55
55
  description: Adds support for creating state machines for attributes on any Ruby class
56
56
  email:
57
57
  - terminale@gmail.com
@@ -76,7 +76,19 @@ files:
76
76
  - lib/state_machines/integrations.rb
77
77
  - lib/state_machines/integrations/base.rb
78
78
  - lib/state_machines/machine.rb
79
+ - lib/state_machines/machine/action_hooks.rb
80
+ - lib/state_machines/machine/callbacks.rb
79
81
  - lib/state_machines/machine/class_methods.rb
82
+ - lib/state_machines/machine/configuration.rb
83
+ - lib/state_machines/machine/event_methods.rb
84
+ - lib/state_machines/machine/helper_generators.rb
85
+ - lib/state_machines/machine/integration.rb
86
+ - lib/state_machines/machine/parsing.rb
87
+ - lib/state_machines/machine/rendering.rb
88
+ - lib/state_machines/machine/scoping.rb
89
+ - lib/state_machines/machine/state_methods.rb
90
+ - lib/state_machines/machine/utilities.rb
91
+ - lib/state_machines/machine/validation.rb
80
92
  - lib/state_machines/machine_collection.rb
81
93
  - lib/state_machines/macro_methods.rb
82
94
  - lib/state_machines/matcher.rb
@@ -89,6 +101,7 @@ files:
89
101
  - lib/state_machines/state_collection.rb
90
102
  - lib/state_machines/state_context.rb
91
103
  - lib/state_machines/stdio_renderer.rb
104
+ - lib/state_machines/syntax_validator.rb
92
105
  - lib/state_machines/test_helper.rb
93
106
  - lib/state_machines/transition.rb
94
107
  - lib/state_machines/transition_collection.rb
@@ -100,6 +113,7 @@ metadata:
100
113
  changelog_uri: https://github.com/state-machines/state_machines/blob/master/CHANGELOG.md
101
114
  homepage_uri: https://github.com/state-machines/state_machines
102
115
  source_code_uri: https://github.com/state-machines/state_machines
116
+ rubygems_mfa_required: 'true'
103
117
  rdoc_options: []
104
118
  require_paths:
105
119
  - lib
@@ -107,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: 3.0.0
124
+ version: 3.2.0
111
125
  required_rubygems_version: !ruby/object:Gem::Requirement
112
126
  requirements:
113
127
  - - ">="
114
128
  - !ruby/object:Gem::Version
115
129
  version: '0'
116
130
  requirements: []
117
- rubygems_version: 3.6.7
131
+ rubygems_version: 3.6.9
118
132
  specification_version: 4
119
133
  summary: State machines for attributes
120
134
  test_files: []