state_machines-activerecord 0.31.0 → 0.100.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8da92c0d0872bf79ae81017dd5d16459e5222d10ee304390ddff3af14f1e1e05
|
4
|
+
data.tar.gz: c7ebd9fbdff4ee5bd2b0cca81b5daad186bb92157eddcb912829685571aa84eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66d176f9efbc9d44ac2d5a5786f078e593d3590a99d855804ff4775649b18abae64264781f4ddc36a60ac253366aea0a9c02d3d1712d680d78fe443fffd437e7
|
7
|
+
data.tar.gz: f5e7a924679499d596439009b9bad2633af5389069959016595d31c44243f7551893cd2e53769e5e1b3a99b979f8d6ad1fa24d86caaa9134f0aa63528739b108
|
data/README.md
CHANGED
@@ -2,9 +2,14 @@
|
|
2
2
|
|
3
3
|
# StateMachines Active Record Integration
|
4
4
|
|
5
|
-
The Active Record
|
5
|
+
The Active Record 7.2+ integration adds support for database transactions, automatically
|
6
6
|
saving the record, named scopes, validation errors.
|
7
7
|
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
- Ruby 3.2+
|
11
|
+
- Rails 7.2+
|
12
|
+
|
8
13
|
## Installation
|
9
14
|
|
10
15
|
Add this line to your application's Gemfile:
|
@@ -428,26 +428,36 @@ module StateMachines
|
|
428
428
|
|
429
429
|
# Runs state events around the machine's :save action
|
430
430
|
def around_save(object, &)
|
431
|
-
|
431
|
+
# Pass fiber: false to avoid deadlocks with ActiveRecord's LoadInterlockAwareMonitor
|
432
|
+
object.class.state_machines.transitions(object, action, fiber: false).perform(&)
|
432
433
|
end
|
433
434
|
|
434
435
|
# Creates a scope for finding records *with* a particular state or
|
435
436
|
# states for the attribute
|
436
437
|
def create_with_scope(name)
|
437
|
-
|
438
|
+
attr_name = attribute
|
439
|
+
lambda do |klass, values|
|
440
|
+
if values.present?
|
441
|
+
klass.where(attr_name => values)
|
442
|
+
else
|
443
|
+
klass.all
|
444
|
+
end
|
445
|
+
end
|
438
446
|
end
|
439
447
|
|
440
448
|
# Creates a scope for finding records *without* a particular state or
|
441
449
|
# states for the attribute
|
442
450
|
def create_without_scope(name)
|
443
|
-
|
451
|
+
attr_name = attribute
|
452
|
+
lambda do |klass, values|
|
453
|
+
if values.present?
|
454
|
+
klass.where.not(attr_name => values)
|
455
|
+
else
|
456
|
+
klass.all
|
457
|
+
end
|
458
|
+
end
|
444
459
|
end
|
445
460
|
|
446
|
-
# Generates the fully-qualifed column name for this machine's attribute
|
447
|
-
def attribute_column
|
448
|
-
connection = owner_class.connection
|
449
|
-
"#{connection.quote_table_name(owner_class.table_name)}.#{connection.quote_column_name(attribute)}"
|
450
|
-
end
|
451
461
|
|
452
462
|
# Runs a new database transaction, rolling back any changes by raising
|
453
463
|
# an ActiveRecord::Rollback exception if the yielded block fails
|
@@ -466,10 +476,6 @@ module StateMachines
|
|
466
476
|
|
467
477
|
private
|
468
478
|
|
469
|
-
# Defines a new scope with the given name
|
470
|
-
def create_scope(_name, scope)
|
471
|
-
->(model, values) { values.present? ? model.where(scope.call(values)) : model.all }
|
472
|
-
end
|
473
479
|
|
474
480
|
# Generates the results for the given scope based on one or more states to filter by
|
475
481
|
def run_scope(scope, machine, klass, states)
|
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.
|
4
|
+
version: 0.100.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.
|
19
|
+
version: '7.2'
|
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.
|
26
|
+
version: '7.2'
|
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.
|
33
|
+
version: 0.100.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.
|
40
|
+
version: 0.100.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: appraisal
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
134
|
requirements:
|
135
135
|
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '3.
|
137
|
+
version: '3.2'
|
138
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
139
|
requirements:
|
140
140
|
- - ">="
|