state_machines 0.100.4 → 0.101.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: 0b9c5ce3b64a05bfea23f266688b2dd1623124d030e4d4eaaa31d0c8b9c5f28c
|
|
4
|
+
data.tar.gz: 3126dccbc693deb8b3255408202400360fdffb14e439eda3923f4c3a320f452f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d6982ddb9e837d4e7d7763b69045733f2751a74a867fa38789f58e7232a96583f7b2336ed8af7d5ebd0196ae58562aa8f19fb7d2f0f79425a1c5c22e6ddda966
|
|
7
|
+
data.tar.gz: 315a781c1daa8f85a6b9f20790245191f5540014fb35b1e2a2a41827828ab7748b33de43e016b088da3054f9ef60b541ba390d492d7aad23f95f546b9b9e933d
|
|
@@ -113,18 +113,10 @@ module StateMachines
|
|
|
113
113
|
# Update all states to reflect the new initial state
|
|
114
114
|
states.each { |state| state.initial = (state.name == @initial_state) }
|
|
115
115
|
|
|
116
|
-
#
|
|
117
|
-
# attribute
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
has_conflicting_default = dynamic_initial_state? || !owner_class_attribute_default_matches?(initial_state)
|
|
121
|
-
return unless has_owner_default && has_conflicting_default
|
|
122
|
-
|
|
123
|
-
warn(
|
|
124
|
-
"Both #{owner_class.name} and its #{name.inspect} machine have defined " \
|
|
125
|
-
"a different default for \"#{attribute}\". Use only one or the other for " \
|
|
126
|
-
'defining defaults to avoid unexpected behaviors.'
|
|
127
|
-
)
|
|
116
|
+
# Warn if the owner class and the machine have conflicting defaults for
|
|
117
|
+
# the machine's attribute. May be deferred by integrations (e.g.
|
|
118
|
+
# ActiveRecord) to avoid touching the DB at class load time.
|
|
119
|
+
schedule_conflicting_attribute_default_check
|
|
128
120
|
end
|
|
129
121
|
|
|
130
122
|
# Gets the attribute name for the given machine scope.
|
|
@@ -58,6 +58,28 @@ module StateMachines
|
|
|
58
58
|
state.matches?(owner_class_attribute_default)
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
# Warns if the owner class and the machine have defined conflicting
|
|
62
|
+
# defaults for the machine's attribute.
|
|
63
|
+
def check_conflicting_attribute_default
|
|
64
|
+
initial_state = states.detect(&:initial)
|
|
65
|
+
has_owner_default = !owner_class_attribute_default.nil?
|
|
66
|
+
has_conflicting_default = dynamic_initial_state? || !owner_class_attribute_default_matches?(initial_state)
|
|
67
|
+
return unless has_owner_default && has_conflicting_default
|
|
68
|
+
|
|
69
|
+
warn(
|
|
70
|
+
"Both #{owner_class.name} and its #{name.inspect} machine have defined " \
|
|
71
|
+
"a different default for \"#{attribute}\". Use only one or the other for " \
|
|
72
|
+
'defining defaults to avoid unexpected behaviors.'
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Schedules or immediately runs the conflicting attribute default check.
|
|
77
|
+
# Override in integrations to defer the check (e.g. until after the DB
|
|
78
|
+
# is ready) to avoid triggering a database connection at class load time.
|
|
79
|
+
def schedule_conflicting_attribute_default_check
|
|
80
|
+
check_conflicting_attribute_default
|
|
81
|
+
end
|
|
82
|
+
|
|
61
83
|
private
|
|
62
84
|
|
|
63
85
|
# Gets the default messages that can be used in the machine for invalid
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'ripper'
|
|
4
|
-
|
|
5
3
|
module StateMachines
|
|
6
4
|
# Cross-platform syntax validation for eval strings
|
|
7
5
|
# Supports CRuby, JRuby, TruffleRuby via pluggable backends
|
|
@@ -15,12 +13,12 @@ module StateMachines
|
|
|
15
13
|
private
|
|
16
14
|
|
|
17
15
|
# Lazily pick the best backend for this platform
|
|
18
|
-
# Prefer RubyVM for performance on CRuby, fallback to
|
|
16
|
+
# Prefer RubyVM for performance on CRuby, fallback to eval for compatibility
|
|
19
17
|
def backend
|
|
20
18
|
@backend ||= if RubyVmBackend.available?
|
|
21
19
|
RubyVmBackend
|
|
22
20
|
else
|
|
23
|
-
|
|
21
|
+
UniversalBackend
|
|
24
22
|
end
|
|
25
23
|
end
|
|
26
24
|
module_function :backend
|
|
@@ -40,16 +38,15 @@ module StateMachines
|
|
|
40
38
|
module_function :validate!
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
# Universal Ruby backend
|
|
44
|
-
module
|
|
41
|
+
# Universal Ruby backend
|
|
42
|
+
module UniversalBackend
|
|
45
43
|
def validate!(code, filename)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
true
|
|
44
|
+
code = code.b
|
|
45
|
+
code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
|
|
46
|
+
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
|
|
47
|
+
}
|
|
48
|
+
code = code.force_encoding(Encoding::UTF_8)
|
|
49
|
+
catch { |tag| eval(code, binding, filename, __LINE__ - 1) } == :ok
|
|
53
50
|
end
|
|
54
51
|
module_function :validate!
|
|
55
52
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: state_machines
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.101.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
@@ -28,16 +28,16 @@ dependencies:
|
|
|
28
28
|
name: minitest
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - '='
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 5.27.0
|
|
34
34
|
type: :development
|
|
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:
|
|
40
|
+
version: 5.27.0
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rake
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
135
135
|
- !ruby/object:Gem::Version
|
|
136
136
|
version: '0'
|
|
137
137
|
requirements: []
|
|
138
|
-
rubygems_version:
|
|
138
|
+
rubygems_version: 4.0.3
|
|
139
139
|
specification_version: 4
|
|
140
140
|
summary: State machines for attributes
|
|
141
141
|
test_files: []
|