state_machines-activerecord 0.200.0 → 0.300.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f022e63c2bfd6af186733c95cbfc19cb7f25dfff128c791e5199b1a3f4e6d760
4
- data.tar.gz: '094b3a2befdd974fa1828e9237f75f0a5a38319b7e38b56b8a3dda376a1e797d'
3
+ metadata.gz: 35ebef64fc42b8b51c00b272365a7fe80b493d82b120ea2a21f9fafef0a0c640
4
+ data.tar.gz: c0a5b6b98eecd70f374c16ba76a590b372edcb0225e117a34d8218418add0113
5
5
  SHA512:
6
- metadata.gz: cfb9f8bca11c37eeaff38ff0a237c2cc241986bba88ee4a8859199ea05ee7d06b4449da73574e0125f678de3082f3ba4e472f491f0efe9100fc2b585cac5e818
7
- data.tar.gz: 8fb449a5ead40d4cf43e92208d307bb34f557e9aae068cda123c968ded28aecfa7a97c416426b04f99afd2550a50b54f852bc6e04c5ab6dc4fef62199d5e615d
6
+ metadata.gz: d636b2fab507273bfd4c0c7b9aca089ce47803fa9de302871e0a31ce02fbeb63776c8f305d724ca1d26a896087f3cd1014c96fbdb13e747529fff2c81a9c9117
7
+ data.tar.gz: 0b8b2ffd5bd9af75a42ef34d15e3b24ae21a5f638a05eb698b463bea07a537aa362898c1d507b3ebe35c778830988e0351dc50af37cae196fefe1b7cd499404f
data/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  # StateMachines Active Record Integration
4
4
 
5
- The Active Record 7.2+ integration adds support for database transactions, automatically
5
+ The Active Record 8.0+ integration adds support for database transactions, automatically
6
6
  saving the record, named scopes, validation errors.
7
7
 
8
8
  ## Requirements
9
9
 
10
10
  - Ruby 3.2+
11
- - Rails 7.2+
11
+ - Rails 8.0+
12
12
 
13
13
  ## Installation
14
14
 
@@ -60,6 +60,116 @@ class Vehicle < ApplicationRecord
60
60
  end
61
61
  ```
62
62
 
63
+ ## State changes go through events
64
+
65
+ The only way to change a record's state through the model is an event:
66
+
67
+ ```ruby
68
+ vehicle.ignite # fire it
69
+ vehicle.ignite! # fire it, raising on refusal
70
+ vehicle.state_event = 'ignite' # queue it for the next save
71
+ vehicle.save
72
+ vehicle.update(state_event: 'ignite')
73
+ ```
74
+
75
+ Writing a *different* state directly raises
76
+ `StateMachines::DirectStateAssignment` before the value changes, whichever
77
+ writer is used: `state=`, mass assignment (`assign_attributes`, `new`,
78
+ `create`, `update`), an attribute alias, `record[:state] =`,
79
+ `write_attribute`, `update_attribute`, or a Rails enum bang method
80
+ (`processing!`). Assigning the state the record already holds (`:parked`,
81
+ `"parked"`, or the stored integer for integer-backed machines) is allowed and
82
+ runs nothing. The error names the machine, the attribute, both values, and
83
+ the alternatives below; a refused assignment is not an event refusal, so no
84
+ `<event>_refusal` reason is recorded.
85
+
86
+ ```ruby
87
+ vehicle = Vehicle.create! # parked
88
+ vehicle.state = 'idling' # => StateMachines::DirectStateAssignment
89
+ vehicle.update(state: 'idling', state_event: 'ignite')
90
+ # => StateMachines::DirectStateAssignment
91
+ ```
92
+
93
+ - New records can be built with their initial state (static, dynamic, or the
94
+ schema default), e.g. `Vehicle.new(state: 'parked')`, but not with another
95
+ one: `Vehicle.create!(state: 'idling')`, `create_with(state: 'idling')` and
96
+ an initializer block writing `idling` all raise.
97
+ - Callbacks are held to the same rule: a `before_transition`,
98
+ `after_transition`, `before_save` or `after_initialize` writing the state
99
+ raises. Only the machine's own writes (initialization, the transition's
100
+ write, rollback after a failure) are authorized, each for that single
101
+ write. Loading from the database, `reload`, `restore_attributes`, `dup`
102
+ and `becomes` keep the state they hold.
103
+ - As a backstop, `save`, `save!`, `save(validate: false)` and
104
+ `update_attribute` refuse to persist a state that changed without going
105
+ through the setter (an in-place mutation, a write to the attribute set),
106
+ and no queued event runs from such a state.
107
+ - `becomes` preserves the state without running transition callbacks, and
108
+ raises `StateMachines::PendingStateEvent` while an event attribute or a
109
+ transition prepared by validation is still queued.
110
+
111
+ ### Forms
112
+
113
+ Expose events, not states. Permit the event attribute and leave the state
114
+ attribute out of strong parameters:
115
+
116
+ ```ruby
117
+ def vehicle_params
118
+ params.require(:vehicle).permit(:name, :state_event)
119
+ end
120
+ ```
121
+
122
+ A form submitting `state` alongside (or instead of) `state_event` gets a
123
+ `DirectStateAssignment` instead of a silent state change.
124
+
125
+ ### Data repair
126
+
127
+ Raw persistence stays outside the state machine on purpose: no event is
128
+ inferred, no callback or validation runs.
129
+
130
+ ```ruby
131
+ vehicle.update_column(:state, 'idling')
132
+ Vehicle.where(id: ids).update_all(state: 'parked')
133
+ Vehicle.upsert_all(rows)
134
+ ActiveRecord::Base.connection.execute("UPDATE vehicles SET state = 'parked' WHERE ...")
135
+ ```
136
+
137
+ Other instances already loaded in memory keep their old state until you
138
+ `reload` them.
139
+
140
+ ### Initial state from the schema default
141
+
142
+ When a machine has no `initial:` option and its attribute has a schema
143
+ default (a database column default, or an Attributes API `default:`) that
144
+ names a defined state, that default is the initial state:
145
+
146
+ ```ruby
147
+ # db/schema.rb
148
+ create_table "accounts" do |t|
149
+ t.string "state", default: "active", null: false
150
+ end
151
+
152
+ class Account < ApplicationRecord
153
+ state_machine do
154
+ state :active, :suspended
155
+ event(:suspend) { transition active: :suspended }
156
+ end
157
+ end
158
+
159
+ Account.new.state # => "active"
160
+ Account.new.suspend # => true
161
+ ```
162
+
163
+ - An explicit static `initial:` always wins over the schema default (and the
164
+ "different default" warning is printed, as before).
165
+ - A dynamic `initial: ->(record) { ... }` only fills a blank attribute, so a
166
+ schema default keeps precedence over it; the warning is printed.
167
+ - The default is read when a record is built, not when the class is loaded,
168
+ so defining the machine before the table exists (e.g. while migrating) is
169
+ fine.
170
+ - A default that names no defined state is ignored: the initial state stays
171
+ `nil` and the "different default" warning is printed at class load.
172
+
63
173
  ### Scopes
64
174
  Usage of the generated scopes (assuming default column `state`):
65
175
 
@@ -119,7 +229,8 @@ When enum integration is detected, the gem automatically:
119
229
  order = Order.create(status: :pending)
120
230
  order.pending? # => true (Rails enum method)
121
231
  order.processing? # => false (Rails enum method)
122
- order.processing! # Sets status to :processing (Rails enum method)
232
+ order.processing! # => StateMachines::DirectStateAssignment (writes the state directly)
233
+ order.process # Fire the event instead
123
234
 
124
235
  Order.pending # Rails enum scope
125
236
  Order.processing # Rails enum scope
@@ -175,11 +286,15 @@ class Order < ApplicationRecord
175
286
  state_machine :status, initial: :pending do
176
287
  state :pending
177
288
  state :approved
289
+
290
+ event :approve do
291
+ transition pending: :approved
292
+ end
178
293
  end
179
294
  end
180
295
 
181
296
  order = Order.create!
182
- order.status = :approved
297
+ order.approve!
183
298
  order.status # => "approved"
184
299
  # The database stores 1.
185
300
  ```
@@ -266,6 +381,74 @@ class Vehicle < ApplicationRecord
266
381
  end
267
382
  ```
268
383
 
384
+ ## Transient state attributes
385
+
386
+ A machine can live on an attribute that is not a database column, either an
387
+ `attr_accessor` or an Attributes API `attribute` with no column behind it:
388
+
389
+ ```ruby
390
+ class Order < ApplicationRecord
391
+ attribute :stage, :string
392
+
393
+ state_machine :stage, initial: ->(order) { order.paid_at ? :paid : :open } do
394
+ state :open, :paid
395
+ end
396
+ end
397
+ ```
398
+
399
+ The initial state is applied to new records *and* to records loaded from the
400
+ database (loading skips `initialize`, so the integration fills the blank
401
+ attribute itself). That happens before `after_find`/`after_initialize`
402
+ callbacks run, so those see the initialized state and may fire events from it
403
+ (writing the state directly raises, as everywhere else). State-scoped validations run
404
+ as they do for column-backed machines, and the attribute's writer follows the
405
+ same [event-only rule](#state-changes-go-through-events) (there is no column,
406
+ so the raw-repair APIs do not apply). Machines on real columns are never
407
+ re-initialized on load: a `NULL` in the database stays `nil`.
408
+
409
+ ## Why an event was refused
410
+
411
+ An event method still returns `false` when it is refused, and `errors` is filled
412
+ as before. The `<event>_refusal` reader from state_machines tells the reasons
413
+ apart (`nil` after a success):
414
+
415
+ | Reason | When |
416
+ |------------------|--------------------------------------------------------------------------|
417
+ | `:no_transition` | No transition for the event from the current state |
418
+ | `:guard` | An `if:`/`unless:` rejected the transition |
419
+ | `:halted` | A `before_transition` returned `false`, or an `around_transition` did not yield |
420
+ | `:action_failed` | `save` returned `false` (validations, a `before_save` that throws `:abort`) or `save!` raised |
421
+
422
+ ```ruby
423
+ vehicle.shift_up # => false
424
+ vehicle.shift_up_refusal # => :action_failed
425
+ vehicle.errors.full_messages # => ["Seatbelt on can't be blank"]
426
+
427
+ vehicle.shift_up! # => StateMachines::InvalidTransition, #reason => :action_failed
428
+
429
+ # Event attributes record the reason too, including when save! raises
430
+ vehicle.state_event = 'shift_up'
431
+ vehicle.save! # => ActiveRecord::RecordInvalid
432
+ vehicle.shift_up_refusal # => :action_failed
433
+ ```
434
+
435
+ In parallel (`fire_events`) only the events that caused the refusal carry a
436
+ reason; a failed `save` is shared, so all of them read `:action_failed`.
437
+
438
+ When `save` fails because another machine's event attribute was refused inside
439
+ it, the fired event carries that reason, matching the bang message:
440
+
441
+ ```ruby
442
+ vehicle.alarm_state_event = 'disable' # its before_transition halts
443
+ vehicle.ignite # => false
444
+ vehicle.ignite_refusal # => :halted (not :action_failed)
445
+ ```
446
+
447
+ `reload` forgets the reasons, and a `dup` / `clone` starts without any. The
448
+ reader reports the most recent attempt on the record, so code firing events on
449
+ one record from several threads should rely on the bang method's
450
+ `InvalidTransition#reason` instead.
451
+
269
452
  ## Contributing
270
453
 
271
454
  1. Fork it ( https://github.com/state-machines/state_machines-activerecord/fork )
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StateMachines
4
+ # Raised when a state machine attribute of an ActiveRecord model is written
5
+ # directly with a different state: through its setter, mass assignment,
6
+ # an attribute alias, +record[:state] =+ or +write_attribute+, while
7
+ # building a record with a state other than its initial state, or when
8
+ # saving a state that was changed without going through the setter.
9
+ #
10
+ # State changes go through events. Raw persistence (+update_column+,
11
+ # +update_columns+, +update_all+, +insert_all+, SQL) stays outside the
12
+ # machine for data repair.
13
+ #
14
+ # A refused assignment is not an event refusal: no refusal reason is
15
+ # recorded for it.
16
+ #
17
+ # @example
18
+ # vehicle.state = 'idling'
19
+ # # => StateMachines::DirectStateAssignment: Cannot assign Vehicle#state
20
+ # # directly from "parked" to "idling" (state machine :state). ...
21
+ class DirectStateAssignment < Error
22
+ # @return [StateMachines::Machine] the machine owning the attribute
23
+ attr_reader :machine
24
+
25
+ # @return [Symbol] the machine's attribute
26
+ attr_reader :attribute
27
+
28
+ # @return [Object] the state value the record holds legitimately
29
+ attr_reader :from
30
+
31
+ # @return [Object] the requested (or bypassed) state value
32
+ attr_reader :to
33
+
34
+ # @param object [ActiveRecord::Base] the record being written
35
+ # @param machine [StateMachines::Machine] the machine owning the attribute
36
+ # @param from [Object] the state value the record holds legitimately
37
+ # @param to [Object] the requested (or bypassed) state value
38
+ def initialize(object, machine:, from:, to:)
39
+ @machine = machine
40
+ @attribute = machine.attribute
41
+ @from = from
42
+ @to = to
43
+
44
+ super(object, build_message(object))
45
+ end
46
+
47
+ private
48
+
49
+ # @param object [ActiveRecord::Base] the record being written
50
+ # @return [String] the error message
51
+ def build_message(object)
52
+ "Cannot assign #{object.class.name}##{attribute} directly from #{from.inspect} to #{to.inspect} " \
53
+ "(state machine #{machine.name.inspect}). State changes go through events: fire one " \
54
+ "(record.<event> / record.<event>!) or set #{machine.attribute(:event)} and save; in forms, " \
55
+ "permit #{machine.attribute(:event)}, not #{attribute}. For data repair outside the state " \
56
+ 'machine use update_column, update_columns, update_all or SQL (no callbacks run), ' \
57
+ 'then reload live instances.'
58
+ end
59
+ end
60
+
61
+ # Raised by +becomes+ while a record still has queued state machine work
62
+ # (a pending event attribute or a transition prepared by validation): the
63
+ # new instance would silently drop it.
64
+ class PendingStateEvent < Error
65
+ # @return [StateMachines::Machine] the machine with queued work
66
+ attr_reader :machine
67
+
68
+ # @return [Symbol, String] the queued event
69
+ attr_reader :event
70
+
71
+ # @param object [ActiveRecord::Base] the record being converted
72
+ # @param machine [StateMachines::Machine] the machine with queued work
73
+ # @param event [Symbol, String] the queued event
74
+ def initialize(object, machine, event)
75
+ @machine = machine
76
+ @event = event
77
+
78
+ super(object, "Cannot call becomes on #{object.class.name} while state machine #{machine.name.inspect} " \
79
+ "has queued work (#{machine.attribute(:event)} = #{event.inspect}); " \
80
+ 'save the record or clear the event first.')
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,449 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'state_machines/integrations/active_record/errors'
4
+
5
+ module StateMachines
6
+ module Integrations
7
+ module ActiveRecord
8
+ # Enforces that state changes through the model are event-only.
9
+ #
10
+ # Every write of a machine's attribute through the model (setter, mass
11
+ # assignment, attribute alias, +record[:attr] =+, +write_attribute+) is
12
+ # checked before the value changes:
13
+ #
14
+ # * writes performed by the machine itself (initialization, a
15
+ # transition persisting its destination, a rollback) are authorized
16
+ # for the duration of that single write only, so callbacks running
17
+ # around a transition cannot overwrite the state;
18
+ # * assigning the value the record already holds (compared through the
19
+ # attribute's type, so +:parked+, +'parked'+ and an integer-backed
20
+ # +0+ are the same) is allowed and runs nothing;
21
+ # * anything else raises {StateMachines::DirectStateAssignment}.
22
+ #
23
+ # While a record is being built, assigned states are collected and,
24
+ # once the machines have initialized, must equal the initial state.
25
+ #
26
+ # As a backstop, saving a record whose state attribute changed without
27
+ # an authorized write (e.g. an in-place mutation or a write straight to
28
+ # the attribute set) raises the same error.
29
+ #
30
+ # Raw persistence (+update_column(s)+, +update_all+, +insert_all+,
31
+ # SQL) and database hydration / +reload+ never go through attribute
32
+ # writers and are left alone.
33
+ module StateGuard
34
+ # Names of attributes the machine is currently writing
35
+ AUTHORIZED_WRITES = :@_state_machines_authorized_writes
36
+
37
+ # Attribute name => last state value written by the machine
38
+ AUTHORIZED_STATES = :@_state_machines_authorized_states
39
+
40
+ # Attribute names assigned while the record is being built
41
+ CONSTRUCTION_WRITES = :@_state_machines_construction_writes
42
+
43
+ # Instance methods mixed into every model owning a state machine.
44
+ module RecordMethods
45
+ # Updates an attribute, refusing a direct change of a state machine
46
+ # attribute.
47
+ #
48
+ # @param attr_name [String, Symbol] attribute (or alias) name
49
+ # @param value [Object] the new value
50
+ # @raise [StateMachines::DirectStateAssignment]
51
+ def write_attribute(attr_name, value)
52
+ name = attr_name.to_s
53
+ StateGuard.check_write!(self, self.class.attribute_aliases[name] || name, value)
54
+ super
55
+ end
56
+
57
+ # @api private
58
+ # @see #write_attribute
59
+ def _write_attribute(attr_name, value)
60
+ StateGuard.check_write!(self, attr_name.to_s, value)
61
+ super
62
+ end
63
+
64
+ # Converts the record to another class, preserving its state.
65
+ #
66
+ # No transition callbacks run, and a state changed without an event
67
+ # stays unauthorized on the new instance.
68
+ #
69
+ # @param klass [Class] the class to convert to
70
+ # @return [ActiveRecord::Base] the converted record
71
+ # @raise [StateMachines::PendingStateEvent] while an event attribute
72
+ # or a transition prepared by validation is queued
73
+ def becomes(klass)
74
+ StateGuard.ensure_no_queued_work!(self)
75
+ super.tap { |became| StateGuard.copy_authorizations(self, became) }
76
+ end
77
+
78
+ # Duplicates the record with its state. Dirty tracking restarts on
79
+ # the copy, so the states the original holds legitimately are
80
+ # authorized on it; a state changed without an event is not.
81
+ #
82
+ # @param other [ActiveRecord::Base] the original record
83
+ # @return [void]
84
+ def initialize_dup(other)
85
+ legitimate = StateGuard.legitimate_states(other)
86
+ super
87
+ remove_instance_variable(AUTHORIZED_WRITES) if instance_variable_defined?(AUTHORIZED_WRITES)
88
+ instance_variable_set(AUTHORIZED_STATES, legitimate)
89
+ end
90
+
91
+ # Reloads the record, forgetting state authorizations: the reloaded
92
+ # attributes are the database's.
93
+ #
94
+ # @return [ActiveRecord::Base] the reloaded record
95
+ def reload(*)
96
+ super.tap { StateGuard.forget(self) }
97
+ end
98
+
99
+ # Forgets state authorizations once changes are persisted.
100
+ #
101
+ # @return [void]
102
+ def changes_applied
103
+ super
104
+ StateGuard.forget(self)
105
+ end
106
+
107
+ # Forgets state authorizations along with the dirty tracking.
108
+ #
109
+ # @return [void]
110
+ def clear_changes_information
111
+ super
112
+ StateGuard.forget(self)
113
+ end
114
+
115
+ private
116
+
117
+ # @see #write_attribute
118
+ def attribute=(attr_name, value)
119
+ StateGuard.check_write!(self, attr_name.to_s, value)
120
+ super
121
+ end
122
+
123
+ # Saves, first refusing state changes made without an event.
124
+ def create_or_update(...)
125
+ StateGuard.verify_persistable!(self)
126
+ super
127
+ end
128
+
129
+ # Checks again once +before_save+ callbacks have run.
130
+ def _create_record(...)
131
+ StateGuard.verify_persistable!(self)
132
+ super
133
+ end
134
+
135
+ # Checks again once +before_save+ callbacks have run.
136
+ def _update_record(...)
137
+ StateGuard.verify_persistable!(self)
138
+ super
139
+ end
140
+
141
+ # Restoring an attribute to its database value is a revert, not a
142
+ # state change, so the write is authorized.
143
+ def restore_attribute!(attr_name)
144
+ StateGuard.authorize(self, attr_name.to_s) { super }
145
+ end
146
+
147
+ # Forgets the authorization of an attribute whose change is cleared
148
+ # (e.g. by +update_columns+).
149
+ def clear_attribute_change(attr_name)
150
+ super
151
+ StateGuard.forget(self, attr_name.to_s)
152
+ end
153
+ end
154
+
155
+ # Guards the writers of machine attributes: the attribute itself,
156
+ # the column it aliases and every alias of that column, whether an
157
+ # ActiveRecord attribute or not (e.g. +attr_accessor+).
158
+ class WriterGuard < Module
159
+ # @return [Set<String>] the attributes whose writers are guarded,
160
+ # aliases resolved
161
+ attr_reader :targets
162
+
163
+ def initialize
164
+ super
165
+ @targets = Set.new
166
+ @writers = Set.new
167
+ end
168
+
169
+ # Guards the writer of +name+.
170
+ #
171
+ # @param name [String] an attribute or alias name
172
+ # @return [void]
173
+ def guard(name)
174
+ return unless @writers.add?(name)
175
+
176
+ define_method(:"#{name}=") do |value|
177
+ StateGuard.check_write!(self, self.class.attribute_aliases[name] || name, value)
178
+ super(value)
179
+ end
180
+ end
181
+ end
182
+
183
+ # Guards writers of aliases declared after the machine.
184
+ module AliasGuard
185
+ # @see ActiveRecord::AttributeMethods::ClassMethods#alias_attribute
186
+ def alias_attribute(new_name, old_name)
187
+ super.tap do
188
+ guard = StateGuard.writer_guard(self)
189
+ target = attribute_aliases.fetch(old_name.to_s, old_name.to_s)
190
+ guard.guard(new_name.to_s) if guard&.targets&.include?(target)
191
+ end
192
+ end
193
+ end
194
+
195
+ class << self
196
+ # Installs the guard on a model class for a machine.
197
+ #
198
+ # @param klass [Class] the model class
199
+ # @param attribute [Symbol] the machine's attribute
200
+ # @return [void]
201
+ def install(klass, attribute)
202
+ klass.include(RecordMethods) unless klass < RecordMethods
203
+ klass.singleton_class.prepend(AliasGuard) unless klass.singleton_class < AliasGuard
204
+ guard = writer_guard(klass) || WriterGuard.new.tap { |mod| klass.prepend(mod) }
205
+
206
+ name = attribute.to_s
207
+ target = klass.attribute_aliases.fetch(name, name)
208
+ guard.targets << target
209
+ [name, target, *klass.attribute_aliases.select { |_, aliased| aliased == target }.keys]
210
+ .each { |writer| guard.guard(writer) }
211
+ end
212
+
213
+ # @param klass [Class] a model class
214
+ # @return [WriterGuard, nil] the writer guard of the class
215
+ def writer_guard(klass)
216
+ klass.ancestors.find { |mod| mod.is_a?(WriterGuard) }
217
+ end
218
+
219
+ # Checks a write of attribute +name+ before it happens.
220
+ #
221
+ # @param record [ActiveRecord::Base] the record being written
222
+ # @param name [String] the attribute name, aliases resolved
223
+ # @param value [Object] the value being written
224
+ # @return [void]
225
+ # @raise [StateMachines::DirectStateAssignment] when the write
226
+ # changes the state of a machine without authorization
227
+ def check_write!(record, name, value)
228
+ machine = machine_for(record, name)
229
+ return unless machine
230
+ return if record.instance_variable_get(AUTHORIZED_WRITES)&.include?(name)
231
+
232
+ if (writes = record.instance_variable_get(CONSTRUCTION_WRITES))
233
+ writes << name
234
+ return
235
+ end
236
+
237
+ current = current_value(record, machine)
238
+ return if same_state?(record, machine, current, value)
239
+
240
+ raise DirectStateAssignment.new(record, machine: machine, from: current, to: value)
241
+ end
242
+
243
+ # Authorizes writes of attribute +name+ for the duration of the
244
+ # block, then remembers the written value as legitimate.
245
+ #
246
+ # @param record [ActiveRecord::Base] the record being written
247
+ # @param name [String] the attribute name, aliases resolved
248
+ # @return [Object] the block's result
249
+ def authorize(record, name)
250
+ writes = record.instance_variable_get(AUTHORIZED_WRITES) ||
251
+ record.instance_variable_set(AUTHORIZED_WRITES, Set.new)
252
+ added = writes.add?(name)
253
+ result = yield
254
+ machine = machine_for(record, name)
255
+ remember(record, name, current_value(record, machine)) if machine
256
+ result
257
+ ensure
258
+ writes.delete(name) if added
259
+ end
260
+
261
+ # Starts collecting state assignments made while building a record.
262
+ #
263
+ # @param record [ActiveRecord::Base] the record being built
264
+ # @return [void]
265
+ def begin_construction(record)
266
+ record.instance_variable_set(CONSTRUCTION_WRITES, Set.new)
267
+ end
268
+
269
+ # Stops collecting state assignments and checks that each assigned
270
+ # state equals the machine's initial state for the record (static,
271
+ # dynamic or schema-default).
272
+ #
273
+ # @param record [ActiveRecord::Base] the record being built
274
+ # @return [void]
275
+ # @raise [StateMachines::DirectStateAssignment] when a state other
276
+ # than the initial one was assigned
277
+ def finish_construction(record)
278
+ writes = record.instance_variable_get(CONSTRUCTION_WRITES)
279
+ record.instance_variable_set(CONSTRUCTION_WRITES, nil)
280
+ return if writes.nil? || writes.empty?
281
+
282
+ # Machines sharing an attribute (e.g. a public and a private
283
+ # machine) share its initial state, set on one of them
284
+ machines = record.class.state_machines.values.group_by { |machine| guarded_name(machine) }
285
+ machines.slice(*writes).each do |name, siblings|
286
+ machine = siblings.find { |sibling| sibling.initial_state(record) } || siblings.first
287
+ current = current_value(record, machine)
288
+ expected = machine.initial_state(record)&.value
289
+ next remember(record, name, current) if same_state?(record, machine, expected, current)
290
+
291
+ raise DirectStateAssignment.new(record, machine: machine, from: expected, to: current)
292
+ end
293
+ end
294
+
295
+ # Refuses to persist a state attribute that changed without an
296
+ # authorized write.
297
+ #
298
+ # @param record [ActiveRecord::Base] the record being saved
299
+ # @return [void]
300
+ # @raise [StateMachines::DirectStateAssignment]
301
+ def verify_persistable!(record)
302
+ each_persisted_state(record) do |machine, name, current, legitimate|
303
+ next if legitimate
304
+
305
+ from = record.attribute_in_database(name)
306
+ raise DirectStateAssignment.new(record, machine: machine, from: from, to: current)
307
+ end
308
+ end
309
+
310
+ # The persisted state attributes whose current value the record
311
+ # holds legitimately: unchanged, or last written by the machine.
312
+ #
313
+ # @param record [ActiveRecord::Base]
314
+ # @return [Hash{String => Object}] attribute name => current value
315
+ def legitimate_states(record)
316
+ states = {}
317
+ each_persisted_state(record) { |_machine, name, current, legitimate| states[name] = current if legitimate }
318
+ states
319
+ end
320
+
321
+ # Like {verify_persistable!}, but only while some machine has an
322
+ # event queued, so no transition starts from an unauthorized state.
323
+ #
324
+ # @param record [ActiveRecord::Base] the record about to transition
325
+ # @return [void]
326
+ def verify_before_transitions!(record)
327
+ verify_persistable!(record) if queued_work(record)
328
+ end
329
+
330
+ # @param record [ActiveRecord::Base] the record being converted
331
+ # @return [void]
332
+ # @raise [StateMachines::PendingStateEvent] when an event attribute
333
+ # or a prepared transition is queued
334
+ def ensure_no_queued_work!(record)
335
+ machine, event = queued_work(record)
336
+ raise PendingStateEvent.new(record, machine, event) if machine
337
+ end
338
+
339
+ # Gives +target+ the same state authorizations as +source+.
340
+ #
341
+ # @return [void]
342
+ def copy_authorizations(source, target)
343
+ target.instance_variable_set(AUTHORIZED_STATES, source.instance_variable_get(AUTHORIZED_STATES)&.dup)
344
+ end
345
+
346
+ # Forgets the remembered state of one or every attribute.
347
+ #
348
+ # @param record [ActiveRecord::Base]
349
+ # @param name [String, nil] the attribute, or nil for all
350
+ # @return [void]
351
+ def forget(record, name = nil)
352
+ authorized = record.instance_variable_get(AUTHORIZED_STATES)
353
+ return unless authorized
354
+
355
+ name ? authorized.delete(name) : authorized.clear
356
+ end
357
+
358
+ # The attribute a machine writes, aliases resolved.
359
+ #
360
+ # @param machine [StateMachines::Machine]
361
+ # @return [String]
362
+ def guarded_name(machine)
363
+ name = machine.attribute.to_s
364
+ machine.owner_class.attribute_aliases.fetch(name, name)
365
+ end
366
+
367
+ private
368
+
369
+ # Yields each database-backed state attribute of the record with
370
+ # its current value and whether the record holds it legitimately.
371
+ #
372
+ # @yieldparam machine [StateMachines::Machine]
373
+ # @yieldparam name [String] the attribute name, aliases resolved
374
+ # @yieldparam current [Object] the current value
375
+ # @yieldparam legitimate [Boolean] unchanged, or last written by
376
+ # the machine
377
+ # @return [void]
378
+ def each_persisted_state(record)
379
+ authorized = record.instance_variable_get(AUTHORIZED_STATES)
380
+ seen = Set.new
381
+
382
+ record.class.state_machines.each_value do |machine|
383
+ name = guarded_name(machine)
384
+ next unless seen.add?(name) && record._has_attribute?(name) && !machine.transient_attribute?
385
+
386
+ current = record._read_attribute(name)
387
+ legitimate = !record.attribute_changed?(name) ||
388
+ (authorized&.key?(name) && same_state?(record, machine, authorized[name], current))
389
+ yield machine, name, current, legitimate
390
+ end
391
+ end
392
+
393
+ # @return [StateMachines::Machine, nil] the first machine writing
394
+ # attribute +name+
395
+ def machine_for(record, name)
396
+ record.class.state_machines.each_value.find { |machine| guarded_name(machine) == name }
397
+ end
398
+
399
+ # @return [Array(StateMachines::Machine, Object), nil] the first
400
+ # machine with queued work and its event
401
+ def queued_work(record)
402
+ record.class.state_machines.each_value do |machine|
403
+ next unless machine.action
404
+
405
+ event = machine.read(record, :event)
406
+ event ||= machine.read(record, :event_transition, true)&.event
407
+ return [machine, event] if event
408
+ end
409
+ nil
410
+ end
411
+
412
+ # @return [Object] the current value of the machine's attribute
413
+ def current_value(record, machine)
414
+ name = guarded_name(machine)
415
+ record._has_attribute?(name) ? record._read_attribute(name) : record.public_send(machine.attribute)
416
+ end
417
+
418
+ # Whether two values denote the same stored state, compared through
419
+ # the attribute's type (symbols and strings, integer-backed states,
420
+ # enums).
421
+ #
422
+ # @return [Boolean]
423
+ def same_state?(record, machine, left, right)
424
+ canonical(record, machine, left) == canonical(record, machine, right)
425
+ end
426
+
427
+ # @return [Object] the value as the attribute would store it
428
+ def canonical(record, machine, value)
429
+ name = guarded_name(machine)
430
+ if record._has_attribute?(name)
431
+ record.class.type_for_attribute(name).cast(value)
432
+ else
433
+ value.is_a?(Symbol) ? value.to_s : value
434
+ end
435
+ end
436
+
437
+ # Remembers +value+ as the legitimate state of attribute +name+.
438
+ #
439
+ # @return [void]
440
+ def remember(record, name, value)
441
+ authorized = record.instance_variable_get(AUTHORIZED_STATES) ||
442
+ record.instance_variable_set(AUTHORIZED_STATES, {})
443
+ authorized[name] = value
444
+ end
445
+ end
446
+ end
447
+ end
448
+ end
449
+ end
@@ -3,7 +3,7 @@
3
3
  module StateMachines
4
4
  module Integrations
5
5
  module ActiveRecord
6
- VERSION = '0.200.0'
6
+ VERSION = '0.300.0'
7
7
  end
8
8
  end
9
9
  end
@@ -4,6 +4,7 @@ require 'state_machines-activemodel'
4
4
  require 'active_record'
5
5
  require 'state_machines/integrations/active_record/version'
6
6
  require 'state_machines/integrations/active_record/type/integer'
7
+ require 'state_machines/integrations/active_record/state_guard'
7
8
 
8
9
  module StateMachines
9
10
  module Integrations # :nodoc:
@@ -109,6 +110,26 @@ module StateMachines
109
110
  # # Control access via strong parameters in your controller
110
111
  # end
111
112
  #
113
+ # == Direct state assignment
114
+ #
115
+ # State changes through the model are event-only. Writing a different
116
+ # state directly (the attribute writer, mass assignment, an alias,
117
+ # <tt>record[:state] =</tt>, +write_attribute+, building a record with a
118
+ # non-initial state, or a callback doing any of these) raises
119
+ # StateMachines::DirectStateAssignment before the value changes, and
120
+ # +save+ refuses to persist a state changed behind the writer's back.
121
+ # Assigning the state the record already holds is allowed and runs
122
+ # nothing.
123
+ #
124
+ # vehicle = Vehicle.create # => #<Vehicle id: 1, name: nil, state: "parked">
125
+ # vehicle.state = 'idling' # => StateMachines::DirectStateAssignment
126
+ # vehicle.ignite # => true
127
+ #
128
+ # Raw persistence (+update_column+, +update_columns+, +update_all+,
129
+ # +insert_all+ / +upsert_all+, SQL) stays outside the machine for data
130
+ # repair: no event is inferred and no callback runs. Reload live
131
+ # instances afterwards. See StateGuard for the details.
132
+ #
112
133
  # == Transactions
113
134
  #
114
135
  # In order to ensure that any changes made during transition callbacks
@@ -183,7 +204,8 @@ module StateMachines
183
204
  #
184
205
  # For example,
185
206
  #
186
- # vehicle = Vehicle.create(:state => 'idling') # => #<Vehicle id: 1, name: nil, state: "idling">
207
+ # vehicle = Vehicle.create # => #<Vehicle id: 1, name: nil, state: "parked">
208
+ # vehicle.ignite # => true
187
209
  # vehicle.ignite # => false
188
210
  # vehicle.errors.full_messages # => ["State cannot transition via \"ignite\""]
189
211
  #
@@ -380,6 +402,18 @@ module StateMachines
380
402
  @defaults = { action: :save, use_transactions: true }
381
403
  @auto_convert_integer_state_attributes = true
382
404
 
405
+ # Forgets the refusal reasons recorded on a record when it is reloaded:
406
+ # they describe attempts made against the state being discarded.
407
+ module RefusalReset
408
+ # Reloads the record and forgets its refusal reasons.
409
+ #
410
+ # @return [ActiveRecord::Base] the reloaded record
411
+ # @see StateMachines::Event#refusal
412
+ def reload(*)
413
+ super.tap { StateMachines::Event.clear_refusals(self) }
414
+ end
415
+ end
416
+
383
417
  # Machine-specific methods for enum integration
384
418
  module MachineMethods
385
419
  # Enum integration metadata storage
@@ -401,10 +435,16 @@ module StateMachines
401
435
  # sees this machine's (cloned) states, picking up subclass-added states
402
436
  # as they are defined.
403
437
  #
438
+ # Also makes reload forget the record's refusal reasons (see
439
+ # {RefusalReset}) and installs the guard making state changes
440
+ # event-only (see {StateGuard}).
441
+ #
404
442
  # @param klass [Class] the new owner class
405
443
  # @return [Class] the assigned owner class
406
444
  def owner_class=(klass)
407
445
  super.tap do
446
+ klass.include(RefusalReset) unless klass < RefusalReset
447
+ StateGuard.install(klass, attribute)
408
448
  register_integer_type if integer_type_registered?
409
449
  end
410
450
  end
@@ -450,11 +490,64 @@ module StateMachines
450
490
  result
451
491
  end
452
492
 
493
+ # Sets the initial state, remembering whether one was configured
494
+ # explicitly. Without an explicit initial state the attribute's schema
495
+ # default may supply it (see {#initial_state}).
496
+ #
497
+ # @param new_initial_state [Symbol, Proc, nil] the initial state name,
498
+ # a lambda resolving it per record, or nil for none
499
+ # @return [Symbol, Proc, nil] the assigned initial state
500
+ def initial_state=(new_initial_state)
501
+ @explicit_initial_state = !new_initial_state.nil?
502
+ super
503
+ end
504
+
505
+ # Gets the initial state for the given record.
506
+ #
507
+ # An explicit +initial:+ (static or dynamic) always wins. Without one,
508
+ # the attribute's schema default (the database column default, or a
509
+ # default declared through the Attributes API) is used when it names a
510
+ # defined state. The default is read lazily, when a record is built, so
511
+ # defining the machine never requires the table to exist. A default
512
+ # that names no defined state is ignored and the initial state stays
513
+ # nil (the class-load conflicting-default warning reports it).
514
+ #
515
+ # @param object [ActiveRecord::Base] the record being initialized
516
+ # @return [StateMachines::State, nil] the initial state
517
+ def initial_state(object)
518
+ return super if explicit_initial_state?
519
+
520
+ schema_default_state || super
521
+ end
522
+
523
+ # Whether the machine's attribute is not backed by a database column
524
+ # (aliases resolve to their target). Reads the class's memoized
525
+ # columns, so it is cheap enough to call for every loaded record.
526
+ # Returns false while the schema cannot be read.
527
+ #
528
+ # @return [Boolean]
529
+ def transient_attribute?
530
+ name = attribute.to_s
531
+ !owner_class.columns_hash.key?(owner_class.attribute_aliases.fetch(name, name))
532
+ rescue ::ActiveRecord::StatementInvalid, ::ActiveRecord::ConnectionNotEstablished
533
+ false
534
+ end
535
+
536
+ # Whether the machine was given an explicit (non-nil) initial state.
537
+ #
538
+ # @return [Boolean]
539
+ def explicit_initial_state?
540
+ !!@explicit_initial_state
541
+ end
542
+
453
543
  # Warns at most once when the column default conflicts with the
454
544
  # machine's initial state. The conflict is re-evaluated as states are
455
- # defined, so remember when the warning has been issued.
545
+ # defined, so remember when the warning has been issued. No warning is
546
+ # issued when the machine has no explicit initial state and the column
547
+ # default names a defined state: the default then *is* the initial
548
+ # state.
456
549
  def check_conflicting_attribute_default
457
- return if @attribute_default_conflict_warned
550
+ return if @attribute_default_conflict_warned || schema_default_initial_state?
458
551
 
459
552
  initial_state = states.detect(&:initial)
460
553
  conflict = !owner_class_attribute_default.nil? && (
@@ -580,6 +673,31 @@ module StateMachines
580
673
  end
581
674
  end
582
675
 
676
+ # Writes a value to the record. A state write is the machine's own
677
+ # (initialization, a transition persisting its destination, a
678
+ # rollback), so it is authorized for the duration of this single
679
+ # write: callbacks running around it are not (see {StateGuard}).
680
+ #
681
+ # @param object [ActiveRecord::Base] record being written
682
+ # @param attr_sym [Symbol] attribute kind (:state, :event, ...)
683
+ # @param value [Object] the value to write
684
+ # @param ivar [Boolean] whether to write an instance variable
685
+ # @return [Object] the written value
686
+ def write(object, attr_sym, value, ivar = false)
687
+ return super unless attr_sym == :state && !ivar
688
+
689
+ StateGuard.authorize(object, StateGuard.guarded_name(self)) { super }
690
+ end
691
+
692
+ # Runs state events around validation, first refusing to start a
693
+ # transition from a state changed without an event.
694
+ #
695
+ # @param object [ActiveRecord::Base] record being validated
696
+ def around_validation(object, &)
697
+ StateGuard.verify_before_transitions!(object)
698
+ super
699
+ end
700
+
583
701
  # Machine internals (state matching, validations) call read() to get the
584
702
  # current state value and compare it against state.value. The custom
585
703
  # integer type already returns the canonical value when state values are
@@ -611,6 +729,24 @@ module StateMachines
611
729
 
612
730
  private
613
731
 
732
+ # Whether the schema default supplies the initial state: there is no
733
+ # explicit initial state and the default names a defined state.
734
+ #
735
+ # @return [Boolean]
736
+ def schema_default_initial_state?
737
+ !explicit_initial_state? && !schema_default_state.nil?
738
+ end
739
+
740
+ # Finds the named state matching the attribute's schema default.
741
+ #
742
+ # @return [StateMachines::State, nil] the matching state, or nil when
743
+ # there is no default (or no readable schema) or it names no state
744
+ def schema_default_state
745
+ return if owner_class_attribute_default.nil?
746
+
747
+ states.detect { |state| state.name && owner_class_attribute_default_matches?(state) }
748
+ end
749
+
614
750
  # Re-runs the conflicting-default check for states defined after
615
751
  # initialization. Skipped until an initial state exists (the DSL block
616
752
  # evaluates before initial_state= during Machine.new).
@@ -817,6 +953,26 @@ module StateMachines
817
953
  def matching_ancestors
818
954
  [::ActiveRecord::Base]
819
955
  end
956
+
957
+ # Initializes the states of a record loaded from the database for the
958
+ # machines whose attribute is not a database column (an
959
+ # +attr_accessor+ or a column-less Attributes API attribute). Loading
960
+ # skips +initialize+, so without this such records would start with a
961
+ # blank state. Column-backed machines are left alone: the stored value,
962
+ # even NULL, is the record's state. Only blank attributes are filled,
963
+ # static initial states before dynamic ones (which may depend on them),
964
+ # and before +after_find+/+after_initialize+ callbacks run, so those
965
+ # callbacks see the initialized state (and may fire events from it).
966
+ # The writes are the machine's own, so they are authorized (see
967
+ # {StateGuard}) and run no callbacks.
968
+ #
969
+ # @param record [ActiveRecord::Base] the record being loaded
970
+ # @return [void]
971
+ def initialize_transient_states(record)
972
+ machines = record.class.state_machines.values.select(&:transient_attribute?)
973
+ static, dynamic = machines.partition { |machine| !machine.dynamic_initial_state? }
974
+ (static + dynamic).each { |machine| machine.initialize_state(record) }
975
+ end
820
976
  end
821
977
 
822
978
  protected
@@ -826,14 +982,20 @@ module StateMachines
826
982
  action == :save
827
983
  end
828
984
 
829
- # Gets the db default for the machine's attribute.
830
- # For integer columns the raw pre-type-registration default is returned so
831
- # that check_conflicting_attribute_default can compare integers to integers.
985
+ # Gets the db default for the machine's attribute, resolving attribute
986
+ # aliases to the underlying column. For integer columns the raw
987
+ # pre-type-registration default is returned so that
988
+ # check_conflicting_attribute_default can compare integers to integers.
989
+ # Returns nil while the schema cannot be read (no connection, no table).
990
+ #
991
+ # @return [Object, nil] the default value
832
992
  def owner_class_attribute_default
833
993
  return @raw_integer_column_default if defined?(@raw_integer_column_default)
834
994
  return unless owner_class.connected? && owner_class.table_exists?
835
995
 
836
- owner_class.column_defaults[attribute.to_s]
996
+ owner_class.column_defaults[owner_class.attribute_aliases.fetch(attribute.to_s, attribute.to_s)]
997
+ rescue ::ActiveRecord::StatementInvalid, ::ActiveRecord::ConnectionNotEstablished
998
+ nil
837
999
  end
838
1000
 
839
1001
  # Checks whether the given state matches the column default. When the
@@ -855,14 +1017,23 @@ module StateMachines
855
1017
  def define_state_initializer
856
1018
  define_helper :instance, <<-END_EVAL, __FILE__, __LINE__ + 1
857
1019
  def initialize(attributes = nil, *)
1020
+ StateMachines::Integrations::ActiveRecord::StateGuard.begin_construction(self)
858
1021
  super(attributes) do |*args|
859
1022
  attributes = (attributes || {}).transform_keys { |key| self.class.attribute_aliases[key.to_s] || key }
860
1023
  scoped_attributes = attributes.merge(self.class.scope_attributes)
861
1024
 
862
1025
  self.class.state_machines.initialize_states(self, {}, scoped_attributes)
1026
+ StateMachines::Integrations::ActiveRecord::StateGuard.finish_construction(self)
863
1027
  yield(*args) if block_given?
864
1028
  end
865
1029
  end
1030
+
1031
+ def init_with_attributes(attributes, new_record = false)
1032
+ super do |record|
1033
+ StateMachines::Integrations::ActiveRecord.initialize_transient_states(record)
1034
+ yield record if block_given?
1035
+ end
1036
+ end
866
1037
  END_EVAL
867
1038
  end
868
1039
 
@@ -890,6 +1061,7 @@ module StateMachines
890
1061
 
891
1062
  # Runs state events around the machine's :save action
892
1063
  def around_save(object, &)
1064
+ StateGuard.verify_before_transitions!(object)
893
1065
  # Pass fiber: false to avoid deadlocks with ActiveRecord's LoadInterlockAwareMonitor
894
1066
  object.class.state_machines.transitions(object, action, fiber: false).perform(&)
895
1067
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.200.0
4
+ version: 0.300.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '7.2'
19
+ version: '8.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '7.2'
26
+ version: '8.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: state_machines-activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.200.0
33
+ version: 0.300.0
34
34
  type: :runtime
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.200.0
40
+ version: 0.300.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: appraisal
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 5.27.0
61
+ version: '6.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 5.27.0
68
+ version: '6.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest-reporters
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -120,7 +120,9 @@ files:
120
120
  - README.md
121
121
  - lib/state_machines-activerecord.rb
122
122
  - lib/state_machines/integrations/active_record.rb
123
+ - lib/state_machines/integrations/active_record/errors.rb
123
124
  - lib/state_machines/integrations/active_record/locale.rb
125
+ - lib/state_machines/integrations/active_record/state_guard.rb
124
126
  - lib/state_machines/integrations/active_record/type/integer.rb
125
127
  - lib/state_machines/integrations/active_record/version.rb
126
128
  homepage: https://github.com/state-machines/state_machines-activerecord/
@@ -135,14 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
137
  requirements:
136
138
  - - ">="
137
139
  - !ruby/object:Gem::Version
138
- version: '3.2'
140
+ version: '4.0'
139
141
  required_rubygems_version: !ruby/object:Gem::Requirement
140
142
  requirements:
141
143
  - - ">="
142
144
  - !ruby/object:Gem::Version
143
145
  version: '0'
144
146
  requirements: []
145
- rubygems_version: 4.0.10
147
+ rubygems_version: 4.0.20
146
148
  specification_version: 4
147
149
  summary: State machines Active Record Integration
148
150
  test_files: []