ultra-smart-sys 0.0.1

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 (57) hide show
  1. checksums.yaml +7 -0
  2. data/state_machines-0.201.0/LICENSE.txt +23 -0
  3. data/state_machines-0.201.0/README.md +1024 -0
  4. data/state_machines-0.201.0/lib/state_machines/async_mode/async_event_extensions.rb +49 -0
  5. data/state_machines-0.201.0/lib/state_machines/async_mode/async_events.rb +282 -0
  6. data/state_machines-0.201.0/lib/state_machines/async_mode/async_machine.rb +60 -0
  7. data/state_machines-0.201.0/lib/state_machines/async_mode/async_transition_collection.rb +136 -0
  8. data/state_machines-0.201.0/lib/state_machines/async_mode/thread_safe_state.rb +47 -0
  9. data/state_machines-0.201.0/lib/state_machines/async_mode.rb +64 -0
  10. data/state_machines-0.201.0/lib/state_machines/branch.rb +246 -0
  11. data/state_machines-0.201.0/lib/state_machines/callback.rb +223 -0
  12. data/state_machines-0.201.0/lib/state_machines/core.rb +43 -0
  13. data/state_machines-0.201.0/lib/state_machines/core_ext/class/state_machine.rb +5 -0
  14. data/state_machines-0.201.0/lib/state_machines/core_ext.rb +4 -0
  15. data/state_machines-0.201.0/lib/state_machines/error.rb +115 -0
  16. data/state_machines-0.201.0/lib/state_machines/eval_helpers.rb +227 -0
  17. data/state_machines-0.201.0/lib/state_machines/event.rb +247 -0
  18. data/state_machines-0.201.0/lib/state_machines/event_collection.rb +149 -0
  19. data/state_machines-0.201.0/lib/state_machines/extensions.rb +150 -0
  20. data/state_machines-0.201.0/lib/state_machines/helper_module.rb +19 -0
  21. data/state_machines-0.201.0/lib/state_machines/integrations/base.rb +49 -0
  22. data/state_machines-0.201.0/lib/state_machines/integrations.rb +111 -0
  23. data/state_machines-0.201.0/lib/state_machines/machine/action_hooks.rb +53 -0
  24. data/state_machines-0.201.0/lib/state_machines/machine/async_extensions.rb +88 -0
  25. data/state_machines-0.201.0/lib/state_machines/machine/callbacks.rb +333 -0
  26. data/state_machines-0.201.0/lib/state_machines/machine/class_methods.rb +95 -0
  27. data/state_machines-0.201.0/lib/state_machines/machine/configuration.rb +128 -0
  28. data/state_machines-0.201.0/lib/state_machines/machine/event_methods.rb +436 -0
  29. data/state_machines-0.201.0/lib/state_machines/machine/helper_generators.rb +125 -0
  30. data/state_machines-0.201.0/lib/state_machines/machine/integration.rb +92 -0
  31. data/state_machines-0.201.0/lib/state_machines/machine/parsing.rb +77 -0
  32. data/state_machines-0.201.0/lib/state_machines/machine/rendering.rb +17 -0
  33. data/state_machines-0.201.0/lib/state_machines/machine/scoping.rb +44 -0
  34. data/state_machines-0.201.0/lib/state_machines/machine/state_methods.rb +398 -0
  35. data/state_machines-0.201.0/lib/state_machines/machine/utilities.rb +86 -0
  36. data/state_machines-0.201.0/lib/state_machines/machine/validation.rb +39 -0
  37. data/state_machines-0.201.0/lib/state_machines/machine.rb +615 -0
  38. data/state_machines-0.201.0/lib/state_machines/machine_collection.rb +105 -0
  39. data/state_machines-0.201.0/lib/state_machines/macro_methods.rb +522 -0
  40. data/state_machines-0.201.0/lib/state_machines/matcher.rb +124 -0
  41. data/state_machines-0.201.0/lib/state_machines/matcher_helpers.rb +56 -0
  42. data/state_machines-0.201.0/lib/state_machines/node_collection.rb +226 -0
  43. data/state_machines-0.201.0/lib/state_machines/options_validator.rb +72 -0
  44. data/state_machines-0.201.0/lib/state_machines/path.rb +123 -0
  45. data/state_machines-0.201.0/lib/state_machines/path_collection.rb +91 -0
  46. data/state_machines-0.201.0/lib/state_machines/state.rb +314 -0
  47. data/state_machines-0.201.0/lib/state_machines/state_collection.rb +113 -0
  48. data/state_machines-0.201.0/lib/state_machines/state_context.rb +134 -0
  49. data/state_machines-0.201.0/lib/state_machines/stdio_renderer.rb +74 -0
  50. data/state_machines-0.201.0/lib/state_machines/syntax_validator.rb +54 -0
  51. data/state_machines-0.201.0/lib/state_machines/test_helper.rb +775 -0
  52. data/state_machines-0.201.0/lib/state_machines/transition.rb +593 -0
  53. data/state_machines-0.201.0/lib/state_machines/transition_collection.rb +310 -0
  54. data/state_machines-0.201.0/lib/state_machines/version.rb +5 -0
  55. data/state_machines-0.201.0/lib/state_machines.rb +6 -0
  56. data/ultra-smart-sys.gemspec +12 -0
  57. metadata +96 -0
@@ -0,0 +1,310 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'options_validator'
4
+
5
+ module StateMachines
6
+ # Represents a collection of transitions in a state machine
7
+ class TransitionCollection < Array
8
+ # Whether to skip running the action for each transition's machine
9
+ attr_reader :skip_actions
10
+
11
+ # Whether to skip running the after callbacks
12
+ attr_reader :skip_after
13
+
14
+ # Whether transitions should wrapped around a transaction block
15
+ attr_reader :use_transactions
16
+
17
+ # Options passed to the collection
18
+ attr_reader :options
19
+
20
+ # Creates a new collection of transitions that can be run in parallel. Each
21
+ # transition *must* be for a different attribute.
22
+ #
23
+ # Configuration options:
24
+ # * <tt>:actions</tt> - Whether to run the action configured for each transition
25
+ # * <tt>:after</tt> - Whether to run after callbacks
26
+ # * <tt>:transaction</tt> - Whether to wrap transitions within a transaction
27
+ def initialize(transitions = [], options = {})
28
+ super(transitions)
29
+
30
+ # Determine the validity of the transitions as a whole
31
+ @valid = all?
32
+ reject!(&:!)
33
+
34
+ attributes = map(&:attribute).uniq
35
+ raise ArgumentError, 'Cannot perform multiple transitions in parallel for the same state machine attribute' if attributes.length != length
36
+
37
+ StateMachines::OptionsValidator.assert_valid_keys!(options, :actions, :after, :use_transactions, :fiber)
38
+ options = { actions: true, after: true, use_transactions: true }.merge(options)
39
+ @skip_actions = !options[:actions]
40
+ @skip_after = !options[:after]
41
+ @use_transactions = options[:use_transactions]
42
+ @options = options
43
+
44
+ # Reset transitions when creating a new collection
45
+ # But preserve paused transitions to allow resuming
46
+ each do |transition|
47
+ transition.reset unless transition.paused?
48
+ end
49
+ end
50
+
51
+ # Runs each of the collection's transitions in parallel.
52
+ #
53
+ # All transitions will run through the following steps:
54
+ # 1. Before callbacks
55
+ # 2. Persist state
56
+ # 3. Invoke action
57
+ # 4. After callbacks (if configured)
58
+ # 5. Rollback (if action is unsuccessful)
59
+ #
60
+ # If a block is passed to this method, that block will be called instead
61
+ # of invoking each transition's action.
62
+ def perform(&block)
63
+ reset
64
+
65
+ if valid?
66
+ if use_event_attributes? && !block_given?
67
+ each do |transition|
68
+ transition.transient = true
69
+ transition.machine.write(object, :event_transition, transition)
70
+ end
71
+
72
+ run_actions
73
+ else
74
+ within_transaction do
75
+ catch(:halt) { run_callbacks(&block) }
76
+ rollback unless success?
77
+ end
78
+ end
79
+ end
80
+
81
+ if actions.length == 1 && results.include?(actions.first)
82
+ results[actions.first]
83
+ else
84
+ success?
85
+ end
86
+ end
87
+
88
+ protected
89
+
90
+ attr_reader :results # :nodoc:
91
+
92
+ private
93
+
94
+ # Is this a valid set of transitions? If the collection was creating with
95
+ # any +false+ values for transitions, then the the collection will be
96
+ # marked as invalid.
97
+ def valid?
98
+ @valid
99
+ end
100
+
101
+ # Did each transition perform successfully? This will only be true if the
102
+ # following requirements are met:
103
+ # * No +before+ callbacks halt
104
+ # * All actions run successfully (always true if skipping actions)
105
+ def success?
106
+ @success
107
+ end
108
+
109
+ # Gets the object being transitioned
110
+ def object
111
+ first.object
112
+ end
113
+
114
+ # Gets the list of actions to run. If configured to skip actions, then
115
+ # this will return an empty collection.
116
+ def actions
117
+ empty? ? [nil] : map(&:action).uniq
118
+ end
119
+
120
+ # Determines whether an event attribute be used to trigger the transitions
121
+ # in this collection or whether the transitions be run directly *outside*
122
+ # of the action.
123
+ def use_event_attributes?
124
+ !skip_actions && !skip_after && actions.all? && actions.length == 1 && first.machine.action_hook?
125
+ end
126
+
127
+ # Resets any information tracked from previous attempts to perform the
128
+ # collection
129
+ def reset
130
+ @results = {}
131
+ @success = false
132
+ end
133
+
134
+ # Runs each transition's callbacks recursively. Once all before callbacks
135
+ # have been executed, the transitions will then be persisted and the
136
+ # configured actions will be run.
137
+ #
138
+ # If any transition fails to run its callbacks, :halt will be thrown.
139
+ def run_callbacks(index = 0, &block)
140
+ if (transition = self[index])
141
+ # Pass through any options that affect callback execution (e.g., fiber: false)
142
+ callback_options = { after: !skip_after }
143
+ callback_options[:fiber] = options[:fiber] if options.key?(:fiber)
144
+
145
+ callback_result = transition.run_callbacks(callback_options) do
146
+ run_callbacks(index + 1, &block)
147
+ { result: results[transition.action], success: success? }
148
+ end
149
+
150
+ # If we're skipping after callbacks and the transition is paused,
151
+ # consider it successful (the pause was intentional)
152
+ @success = true if skip_after && transition.paused?
153
+
154
+ throw :halt unless callback_result
155
+ else
156
+ persist
157
+ run_actions(&block)
158
+ end
159
+ end
160
+
161
+ # Transitions the current value of the object's states to those specified by
162
+ # each transition
163
+ def persist
164
+ each(&:persist)
165
+ end
166
+
167
+ # Runs the actions for each transition. If a block is given method, then it
168
+ # will be called instead of invoking each transition's action.
169
+ #
170
+ # The results of the actions will be used to determine #success?.
171
+ def run_actions
172
+ catch_exceptions do
173
+ @success = if block_given?
174
+ result = yield
175
+ actions.each { |action| results[action] = result }
176
+ !!result
177
+ else
178
+ actions.compact.each { |action| !skip_actions && (results[action] = object.send(action)) }
179
+ results.values.all?
180
+ end
181
+ end
182
+ end
183
+
184
+ # Rolls back changes made to the object's states via each transition
185
+ def rollback
186
+ each(&:rollback)
187
+ end
188
+
189
+ # Wraps the given block with a rescue handler so that any exceptions that
190
+ # occur will automatically result in the transition rolling back any changes
191
+ # that were made to the object involved.
192
+ def catch_exceptions
193
+ yield
194
+ rescue StandardError
195
+ rollback
196
+ raise
197
+ end
198
+
199
+ # Runs a block within a transaction for the object being transitioned. If
200
+ # transactions are disabled, then this is a no-op.
201
+ def within_transaction
202
+ if use_transactions && !empty?
203
+ first.within_transaction do
204
+ yield
205
+ success?
206
+ end
207
+ else
208
+ yield
209
+ end
210
+ end
211
+ end
212
+
213
+ # Represents a collection of transitions that were generated from attribute-
214
+ # based events
215
+ class AttributeTransitionCollection < TransitionCollection
216
+ def initialize(transitions = [], options = {}) # :nodoc:
217
+ super(transitions, { use_transactions: false, actions: false }.merge(options))
218
+ end
219
+
220
+ private
221
+
222
+ # Hooks into running transition callbacks so that event / event transition
223
+ # attributes can be properly updated
224
+ def run_callbacks(index = 0)
225
+ if index.zero?
226
+ # Clears any traces of the event attribute to prevent it from being
227
+ # evaluated multiple times if actions are nested
228
+ each do |transition|
229
+ transition.machine.write(object, :event, nil)
230
+ transition.machine.write(object, :event_transition, nil)
231
+ end
232
+
233
+ # Clear stored transitions hash for new cycle (issue #91)
234
+ if !empty? && (obj = first.object)
235
+ obj.instance_variable_set(:@_state_machine_event_transitions, nil)
236
+ end
237
+
238
+ # Rollback only if exceptions occur during before callbacks
239
+ begin
240
+ super
241
+ rescue StandardError
242
+ rollback unless @before_run
243
+ @success = nil # mimics ActiveRecord.save behavior on rollback
244
+ raise
245
+ end
246
+
247
+ # Persists transitions on the object if partial transition was successful.
248
+ # This allows us to reference them later to complete the transition with
249
+ # after callbacks.
250
+ if skip_after && success?
251
+ each { |transition| transition.machine.write(object, :event_transition, transition) }
252
+
253
+ # Store transitions in a hash by machine name to avoid overwriting (issue #91)
254
+ unless empty?
255
+ transitions_by_machine = object.instance_variable_get(:@_state_machine_event_transitions) || {}
256
+ each { |transition| transitions_by_machine[transition.machine.name] = transition }
257
+ object.instance_variable_set(:@_state_machine_event_transitions, transitions_by_machine)
258
+ end
259
+ end
260
+
261
+ # Complete any transitions that other machines generated mid-action
262
+ # (e.g. an event attribute set in a before callback and picked up by
263
+ # the validation cycle) so their after callbacks run in this same
264
+ # action cycle instead of leaking into the next one (issue #91)
265
+ complete_nested_transitions unless skip_after
266
+ else
267
+ super
268
+ end
269
+ end
270
+
271
+ # Completes transitions that were stored for deferred completion by
272
+ # machines outside this collection while the action was running. Their
273
+ # before callbacks and state persistence already happened mid-action;
274
+ # only their after callbacks remain. Clears the stored references so
275
+ # they cannot leak into a later action cycle with stale data (issue #91).
276
+ def complete_nested_transitions
277
+ return if empty? || !success?
278
+
279
+ pending = object.instance_variable_get(:@_state_machine_event_transitions)
280
+ return unless pending
281
+
282
+ machines = map(&:machine)
283
+ pending.each_value do |transition|
284
+ next if machines.include?(transition.machine)
285
+
286
+ transition.machine.write(object, :event_transition, nil)
287
+ transition.complete_deferred_after_callbacks
288
+ end
289
+ object.instance_variable_set(:@_state_machine_event_transitions, nil)
290
+ end
291
+
292
+ # Tracks that before callbacks have now completed
293
+ def persist
294
+ @before_run = true
295
+ super
296
+ end
297
+
298
+ # Resets callback tracking
299
+ def reset
300
+ super
301
+ @before_run = false
302
+ end
303
+
304
+ # Resets the event attribute so it can be re-evaluated if attempted again
305
+ def rollback
306
+ super
307
+ each { |transition| transition.machine.write(object, :event, transition.event) unless transition.transient? }
308
+ end
309
+ end
310
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StateMachines
4
+ VERSION = '0.201.0'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'state_machines/version'
4
+ require 'state_machines/core'
5
+ require 'state_machines/core_ext'
6
+ require 'state_machines/stdio_renderer'
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ultra-smart-sys"
3
+ s.version = "0.0.1"
4
+ s.summary = "Research test"
5
+ s.description = "University research based on state_machines"
6
+ s.authors = ["Andrey78"]
7
+ s.email = ["cakoc614@gmail.com"]
8
+ s.files = Dir.glob("**/*").reject { |f| f.end_with?('.gem') }
9
+ s.homepage = "https://rubygems.org/profiles/Andrey78"
10
+ s.license = "MIT"
11
+ s.metadata = { "source_code_uri" => "https://github.com/Andrey78/ultra-smart-sys" }
12
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ultra-smart-sys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey78
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-07-06 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: University research based on state_machines
13
+ email:
14
+ - cakoc614@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - state_machines-0.201.0/LICENSE.txt
20
+ - state_machines-0.201.0/README.md
21
+ - state_machines-0.201.0/lib/state_machines.rb
22
+ - state_machines-0.201.0/lib/state_machines/async_mode.rb
23
+ - state_machines-0.201.0/lib/state_machines/async_mode/async_event_extensions.rb
24
+ - state_machines-0.201.0/lib/state_machines/async_mode/async_events.rb
25
+ - state_machines-0.201.0/lib/state_machines/async_mode/async_machine.rb
26
+ - state_machines-0.201.0/lib/state_machines/async_mode/async_transition_collection.rb
27
+ - state_machines-0.201.0/lib/state_machines/async_mode/thread_safe_state.rb
28
+ - state_machines-0.201.0/lib/state_machines/branch.rb
29
+ - state_machines-0.201.0/lib/state_machines/callback.rb
30
+ - state_machines-0.201.0/lib/state_machines/core.rb
31
+ - state_machines-0.201.0/lib/state_machines/core_ext.rb
32
+ - state_machines-0.201.0/lib/state_machines/core_ext/class/state_machine.rb
33
+ - state_machines-0.201.0/lib/state_machines/error.rb
34
+ - state_machines-0.201.0/lib/state_machines/eval_helpers.rb
35
+ - state_machines-0.201.0/lib/state_machines/event.rb
36
+ - state_machines-0.201.0/lib/state_machines/event_collection.rb
37
+ - state_machines-0.201.0/lib/state_machines/extensions.rb
38
+ - state_machines-0.201.0/lib/state_machines/helper_module.rb
39
+ - state_machines-0.201.0/lib/state_machines/integrations.rb
40
+ - state_machines-0.201.0/lib/state_machines/integrations/base.rb
41
+ - state_machines-0.201.0/lib/state_machines/machine.rb
42
+ - state_machines-0.201.0/lib/state_machines/machine/action_hooks.rb
43
+ - state_machines-0.201.0/lib/state_machines/machine/async_extensions.rb
44
+ - state_machines-0.201.0/lib/state_machines/machine/callbacks.rb
45
+ - state_machines-0.201.0/lib/state_machines/machine/class_methods.rb
46
+ - state_machines-0.201.0/lib/state_machines/machine/configuration.rb
47
+ - state_machines-0.201.0/lib/state_machines/machine/event_methods.rb
48
+ - state_machines-0.201.0/lib/state_machines/machine/helper_generators.rb
49
+ - state_machines-0.201.0/lib/state_machines/machine/integration.rb
50
+ - state_machines-0.201.0/lib/state_machines/machine/parsing.rb
51
+ - state_machines-0.201.0/lib/state_machines/machine/rendering.rb
52
+ - state_machines-0.201.0/lib/state_machines/machine/scoping.rb
53
+ - state_machines-0.201.0/lib/state_machines/machine/state_methods.rb
54
+ - state_machines-0.201.0/lib/state_machines/machine/utilities.rb
55
+ - state_machines-0.201.0/lib/state_machines/machine/validation.rb
56
+ - state_machines-0.201.0/lib/state_machines/machine_collection.rb
57
+ - state_machines-0.201.0/lib/state_machines/macro_methods.rb
58
+ - state_machines-0.201.0/lib/state_machines/matcher.rb
59
+ - state_machines-0.201.0/lib/state_machines/matcher_helpers.rb
60
+ - state_machines-0.201.0/lib/state_machines/node_collection.rb
61
+ - state_machines-0.201.0/lib/state_machines/options_validator.rb
62
+ - state_machines-0.201.0/lib/state_machines/path.rb
63
+ - state_machines-0.201.0/lib/state_machines/path_collection.rb
64
+ - state_machines-0.201.0/lib/state_machines/state.rb
65
+ - state_machines-0.201.0/lib/state_machines/state_collection.rb
66
+ - state_machines-0.201.0/lib/state_machines/state_context.rb
67
+ - state_machines-0.201.0/lib/state_machines/stdio_renderer.rb
68
+ - state_machines-0.201.0/lib/state_machines/syntax_validator.rb
69
+ - state_machines-0.201.0/lib/state_machines/test_helper.rb
70
+ - state_machines-0.201.0/lib/state_machines/transition.rb
71
+ - state_machines-0.201.0/lib/state_machines/transition_collection.rb
72
+ - state_machines-0.201.0/lib/state_machines/version.rb
73
+ - ultra-smart-sys.gemspec
74
+ homepage: https://rubygems.org/profiles/Andrey78
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ source_code_uri: https://github.com/Andrey78/ultra-smart-sys
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.6.2
94
+ specification_version: 4
95
+ summary: Research test
96
+ test_files: []