has_state_machine 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f5dce90790fc426f0030f3052f7a09aecc373c5cf71185e4d7a2b22280e834d
|
4
|
+
data.tar.gz: e41c13e77237380c39f420797f2f151a3e615390c3966ac196432f1805370357
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78b889ab38cc3aa0bbf1c7c6f43918894a4afab27be0a4c70ac223b58d8d71521154988ba23c4596110c760295dacdc87005fe67b9709edb894c5c7c64f822ba
|
7
|
+
data.tar.gz: 2e5b88c5c7866ce435593a05d9117fe69839e3f01cba591744466ac91cbcb6e26ac700bea31282e3a6c12d04db3c6ab025a7b2a8bf62ced6f91e96ae17babd05
|
@@ -36,28 +36,28 @@ module HasStateMachine
|
|
36
36
|
def define_helper_methods(states:, options:)
|
37
37
|
##
|
38
38
|
# The list of possible states in the state machine.
|
39
|
-
define_singleton_method
|
39
|
+
define_singleton_method :workflow_states do
|
40
40
|
states
|
41
41
|
end
|
42
42
|
|
43
43
|
##
|
44
44
|
# Defines the column name for the attribute holding the current status.
|
45
45
|
# Can be overwritten to use a different column name.
|
46
|
-
define_singleton_method
|
46
|
+
define_singleton_method :state_attribute do
|
47
47
|
options[:state_attribute]&.to_sym || :status
|
48
48
|
end
|
49
49
|
|
50
50
|
##
|
51
51
|
# Defines the namespace of the models possible states.
|
52
52
|
# Can be overwritten to use a different namespace.
|
53
|
-
define_singleton_method
|
54
|
-
|
53
|
+
define_singleton_method :workflow_namespace do
|
54
|
+
options[:workflow_namespace] || "Workflow::#{self}"
|
55
55
|
end
|
56
56
|
|
57
57
|
##
|
58
58
|
# Determines whether or not the state validations should be run
|
59
59
|
# as part of the object validations; they are by default.
|
60
|
-
define_singleton_method
|
60
|
+
define_singleton_method :state_validations_on_object? do
|
61
61
|
return true unless options.key?(:state_validations_on_object)
|
62
62
|
|
63
63
|
options[:state_validations_on_object]
|
@@ -33,7 +33,7 @@ module HasStateMachine
|
|
33
33
|
def initialize(object)
|
34
34
|
@object = object
|
35
35
|
|
36
|
-
super
|
36
|
+
super(state)
|
37
37
|
end
|
38
38
|
|
39
39
|
##
|
@@ -83,6 +83,8 @@ module HasStateMachine
|
|
83
83
|
rollback_transition unless object.update("#{object.state_attribute}": state)
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
object.reload.public_send(object.state_attribute) == state
|
86
88
|
end
|
87
89
|
|
88
90
|
private
|
@@ -56,7 +56,7 @@ module HasStateMachine
|
|
56
56
|
# > Post.published.where(user: user)
|
57
57
|
# #=> [#<Post>]
|
58
58
|
if defined?(ActiveRecord) && (self < ActiveRecord::Base)
|
59
|
-
scope state, -> { where("#{state_attribute} = ?", state) }
|
59
|
+
scope state, -> { where("#{table_name}.#{state_attribute} = ?", state) }
|
60
60
|
end
|
61
61
|
|
62
62
|
##
|
@@ -67,7 +67,7 @@ module HasStateMachine
|
|
67
67
|
# @example Check if a post is published
|
68
68
|
# > post.published?
|
69
69
|
# #=> true
|
70
|
-
define_method "#{state}?" do
|
70
|
+
define_method :"#{state}?" do
|
71
71
|
current_state == state
|
72
72
|
end
|
73
73
|
end
|
@@ -78,7 +78,7 @@ module HasStateMachine
|
|
78
78
|
# Getter for the current state of the model based on the configured state
|
79
79
|
# attribute.
|
80
80
|
def current_state
|
81
|
-
|
81
|
+
self[state_attribute]
|
82
82
|
end
|
83
83
|
|
84
84
|
##
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_state_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Hargett
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -29,16 +29,16 @@ dependencies:
|
|
29
29
|
name: sqlite3
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '1.4'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '1.4'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: pry
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
|
-
rubygems_version: 3.1.
|
137
|
+
rubygems_version: 3.1.6
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Class based state machine for ActiveRecord models.
|