can_has_state 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 +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +1 -1
- data/lib/can_has_state.rb +3 -0
- data/lib/can_has_state/definition.rb +1 -1
- data/lib/can_has_state/locale/en.yml +5 -0
- data/lib/can_has_state/locale/es.yml +5 -0
- data/lib/can_has_state/machine.rb +9 -5
- data/lib/can_has_state/version.rb +1 -1
- data/test/can_has_state_test.rb +2 -2
- metadata +14 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a3b45a0fd9887bd419ffa6fc89e6a7a566878fbfc8c60f4c34c3e5717659087c
|
4
|
+
data.tar.gz: 57b418edcb7d1403b7e57b5fb1f5665e3cf8fc4b2e68612d56c17627ff16cece
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bbdc97653a0d9087808667b1a26c28f7e2a6f8a2088f315bebad7da575ef31f2cb73e62858cf77875c562496a185e9668984f272c8e2de422cc16de272b86ce
|
7
|
+
data.tar.gz: b69e6e85fc0937e3a9437f747d590ed9f532677b6004f15946c3f2fae6573728a530ada4d1827e15777b4f3a4063d941a5170f9bc83f9070246a6ca39000a3ad
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
data/lib/can_has_state.rb
CHANGED
@@ -28,7 +28,7 @@ module CanHasState
|
|
28
28
|
|
29
29
|
# TODO: turn even guards into types of triggers ... then support :guard as a trigger param
|
30
30
|
guards = []
|
31
|
-
message =
|
31
|
+
message = :invalid_transition
|
32
32
|
# TODO: differentiate messages for :from errors vs. :guard errors
|
33
33
|
|
34
34
|
options.each do |key, val|
|
@@ -71,7 +71,11 @@ module CanHasState
|
|
71
71
|
# clear record of called triggers
|
72
72
|
@triggers_called[column] = nil
|
73
73
|
|
74
|
-
|
74
|
+
if respond_to?("#{column}_before_last_save") # rails 5.1+
|
75
|
+
from, to = send("#{column}_before_last_save"), send(column)
|
76
|
+
else
|
77
|
+
from, to = send("#{column}_was"), send(column)
|
78
|
+
end
|
75
79
|
next if from == to
|
76
80
|
sm.trigger(self, from, to, :deferred)
|
77
81
|
end
|
@@ -83,17 +87,17 @@ module CanHasState
|
|
83
87
|
from, to = send("#{column}_was"), send(column)
|
84
88
|
next if from == to
|
85
89
|
if !sm.known?(to)
|
86
|
-
err << [column,
|
90
|
+
err << [column, :invalid_state]
|
87
91
|
elsif !sm.allow?(self, to) #state_machine_allow?(column, to)
|
88
|
-
err << [column, sm.message(to)
|
92
|
+
err << [column, sm.message(to), {from: from, to: to}]
|
89
93
|
end
|
90
94
|
end
|
91
95
|
err
|
92
96
|
end
|
93
97
|
|
94
98
|
def can_has_valid_state_machines
|
95
|
-
can_has_state_errors.each do |(column, msg)|
|
96
|
-
errors.add column, msg
|
99
|
+
can_has_state_errors.each do |(column, msg, opts)|
|
100
|
+
errors.add column, msg, opts||{}
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
data/test/can_has_state_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_has_state
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -16,40 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '6'
|
22
|
+
version: '6.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '6'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: activesupport
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '4'
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '6'
|
43
|
-
type: :runtime
|
44
|
-
prerelease: false
|
45
|
-
version_requirements: !ruby/object:Gem::Requirement
|
46
|
-
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '4'
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '6'
|
32
|
+
version: '6.2'
|
53
33
|
- !ruby/object:Gem::Dependency
|
54
34
|
name: minitest
|
55
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,6 +73,8 @@ files:
|
|
93
73
|
- lib/can_has_state.rb
|
94
74
|
- lib/can_has_state/definition.rb
|
95
75
|
- lib/can_has_state/dirty_helper.rb
|
76
|
+
- lib/can_has_state/locale/en.yml
|
77
|
+
- lib/can_has_state/locale/es.yml
|
96
78
|
- lib/can_has_state/machine.rb
|
97
79
|
- lib/can_has_state/railtie.rb
|
98
80
|
- lib/can_has_state/version.rb
|
@@ -100,9 +82,10 @@ files:
|
|
100
82
|
- test/can_has_state_test.rb
|
101
83
|
- test/test_helper.rb
|
102
84
|
homepage: https://github.com/zarqman/can_has_state
|
103
|
-
licenses:
|
85
|
+
licenses:
|
86
|
+
- MIT
|
104
87
|
metadata: {}
|
105
|
-
post_install_message:
|
88
|
+
post_install_message:
|
106
89
|
rdoc_options: []
|
107
90
|
require_paths:
|
108
91
|
- lib
|
@@ -117,9 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
100
|
- !ruby/object:Gem::Version
|
118
101
|
version: '0'
|
119
102
|
requirements: []
|
120
|
-
|
121
|
-
|
122
|
-
signing_key:
|
103
|
+
rubygems_version: 3.0.9
|
104
|
+
signing_key:
|
123
105
|
specification_version: 4
|
124
106
|
summary: Super simple state machine for ActiveModel
|
125
107
|
test_files:
|