stator 0.5.0 → 0.9.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +8 -2
- data/.gitignore +1 -0
- data/Appraisals +4 -0
- data/Gemfile +1 -0
- data/gemfiles/activerecord_5.1.gemfile +1 -0
- data/gemfiles/activerecord_5.1.gemfile.lock +12 -2
- data/gemfiles/activerecord_5.2.gemfile +1 -0
- data/gemfiles/activerecord_5.2.gemfile.lock +12 -2
- data/gemfiles/activerecord_5.gemfile +12 -0
- data/gemfiles/activerecord_5.gemfile.lock +74 -0
- data/gemfiles/activerecord_6.0.gemfile +1 -0
- data/gemfiles/activerecord_6.0.gemfile.lock +12 -2
- data/gemfiles/activerecord_6.1.gemfile +1 -0
- data/gemfiles/activerecord_6.1.gemfile.lock +12 -2
- data/gemfiles/activerecord_7.0.gemfile +1 -0
- data/gemfiles/activerecord_7.0.gemfile.lock +12 -2
- data/lib/stator/alias.rb +51 -30
- data/lib/stator/integration.rb +42 -49
- data/lib/stator/machine.rb +59 -58
- data/lib/stator/model.rb +78 -73
- data/lib/stator/transition.rb +61 -60
- data/lib/stator/version.rb +3 -5
- data/lib/stator.rb +13 -0
- data/spec/model_spec.rb +203 -239
- data/spec/spec_helper.rb +6 -3
- data/spec/support/models.rb +26 -45
- data/spec/support/schema.rb +42 -42
- data/stator.gemspec +1 -1
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11dfad97bef44bb60c060b086dce2f327f2fca47d309510337533f31f62e105f
|
4
|
+
data.tar.gz: 578888569b569b4e35c7c180ed3ddfe96ea4547f296394c2c81fbc44bee72105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 959635a8a2eebce12473a7f79844e25de1038fe3a1e692fa97e5d1edc430778a3148a4a7b6ca2e488f248c318a19d74fb69c489c28928ff44731c0e3e8319823
|
7
|
+
data.tar.gz: a13fa8a216bc2fd590d1abea7be2eab258a5e29b58c0017314a083938b5c6f6f0acebf3179b5c4cf7b122dbc2a62ba1342bdc0937fed82365ad2b23d49ce3201
|
data/.github/workflows/build.yml
CHANGED
@@ -3,15 +3,21 @@ on:
|
|
3
3
|
pull_request:
|
4
4
|
push:
|
5
5
|
branches:
|
6
|
-
-
|
6
|
+
- master
|
7
7
|
jobs:
|
8
8
|
build:
|
9
9
|
runs-on: ubuntu-latest
|
10
|
+
continue-on-error: ${{ matrix.experimental }}
|
10
11
|
strategy:
|
11
12
|
fail-fast: false
|
12
13
|
matrix:
|
13
|
-
ruby-version: [2.7.5]
|
14
|
+
ruby-version: [2.7.5, 2.7.6]
|
14
15
|
experimental: [false]
|
16
|
+
include:
|
17
|
+
- ruby-version: 3.0
|
18
|
+
experimental: true
|
19
|
+
- ruby-version: 3.1
|
20
|
+
experimental: true
|
15
21
|
steps:
|
16
22
|
- uses: actions/checkout@v2
|
17
23
|
- uses: ruby/setup-ruby@v1
|
data/.gitignore
CHANGED
data/Appraisals
CHANGED
data/Gemfile
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
stator (0.
|
4
|
+
stator (0.9.0.beta)
|
5
5
|
activerecord
|
6
|
+
activesupport
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -26,11 +27,19 @@ GEM
|
|
26
27
|
thor (>= 0.14.0)
|
27
28
|
arel (8.0.0)
|
28
29
|
concurrent-ruby (1.1.10)
|
30
|
+
debug (1.6.1)
|
31
|
+
irb (>= 1.3.6)
|
32
|
+
reline (>= 0.3.1)
|
29
33
|
diff-lcs (1.5.0)
|
30
34
|
i18n (1.12.0)
|
31
35
|
concurrent-ruby (~> 1.0)
|
36
|
+
io-console (0.5.11)
|
37
|
+
irb (1.4.1)
|
38
|
+
reline (>= 0.3.0)
|
32
39
|
minitest (5.16.2)
|
33
40
|
rake (13.0.6)
|
41
|
+
reline (0.3.1)
|
42
|
+
io-console (~> 0.5)
|
34
43
|
rspec (3.11.0)
|
35
44
|
rspec-core (~> 3.11.0)
|
36
45
|
rspec-expectations (~> 3.11.0)
|
@@ -56,9 +65,10 @@ DEPENDENCIES
|
|
56
65
|
activerecord (~> 5.1.0)
|
57
66
|
activerecord-nulldb-adapter
|
58
67
|
appraisal
|
68
|
+
debug
|
59
69
|
rake
|
60
70
|
rspec
|
61
71
|
stator!
|
62
72
|
|
63
73
|
BUNDLED WITH
|
64
|
-
2.3.
|
74
|
+
2.3.16
|
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
stator (0.
|
4
|
+
stator (0.9.0.beta)
|
5
5
|
activerecord
|
6
|
+
activesupport
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -26,11 +27,19 @@ GEM
|
|
26
27
|
thor (>= 0.14.0)
|
27
28
|
arel (9.0.0)
|
28
29
|
concurrent-ruby (1.1.10)
|
30
|
+
debug (1.6.1)
|
31
|
+
irb (>= 1.3.6)
|
32
|
+
reline (>= 0.3.1)
|
29
33
|
diff-lcs (1.5.0)
|
30
34
|
i18n (1.12.0)
|
31
35
|
concurrent-ruby (~> 1.0)
|
36
|
+
io-console (0.5.11)
|
37
|
+
irb (1.4.1)
|
38
|
+
reline (>= 0.3.0)
|
32
39
|
minitest (5.16.2)
|
33
40
|
rake (13.0.6)
|
41
|
+
reline (0.3.1)
|
42
|
+
io-console (~> 0.5)
|
34
43
|
rspec (3.11.0)
|
35
44
|
rspec-core (~> 3.11.0)
|
36
45
|
rspec-expectations (~> 3.11.0)
|
@@ -56,9 +65,10 @@ DEPENDENCIES
|
|
56
65
|
activerecord (~> 5.2.0)
|
57
66
|
activerecord-nulldb-adapter
|
58
67
|
appraisal
|
68
|
+
debug
|
59
69
|
rake
|
60
70
|
rspec
|
61
71
|
stator!
|
62
72
|
|
63
73
|
BUNDLED WITH
|
64
|
-
2.3.
|
74
|
+
2.3.16
|
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
stator (0.9.0.beta)
|
5
|
+
activerecord
|
6
|
+
activesupport
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.0.7.2)
|
12
|
+
activesupport (= 5.0.7.2)
|
13
|
+
activerecord (5.0.7.2)
|
14
|
+
activemodel (= 5.0.7.2)
|
15
|
+
activesupport (= 5.0.7.2)
|
16
|
+
arel (~> 7.0)
|
17
|
+
activerecord-nulldb-adapter (0.4.0)
|
18
|
+
activerecord (>= 2.0.0)
|
19
|
+
activesupport (5.0.7.2)
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
i18n (>= 0.7, < 2)
|
22
|
+
minitest (~> 5.1)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
appraisal (2.4.1)
|
25
|
+
bundler
|
26
|
+
rake
|
27
|
+
thor (>= 0.14.0)
|
28
|
+
arel (7.1.4)
|
29
|
+
concurrent-ruby (1.1.10)
|
30
|
+
debug (1.6.1)
|
31
|
+
irb (>= 1.3.6)
|
32
|
+
reline (>= 0.3.1)
|
33
|
+
diff-lcs (1.5.0)
|
34
|
+
i18n (1.12.0)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
io-console (0.5.11)
|
37
|
+
irb (1.4.1)
|
38
|
+
reline (>= 0.3.0)
|
39
|
+
minitest (5.16.2)
|
40
|
+
rake (13.0.6)
|
41
|
+
reline (0.3.1)
|
42
|
+
io-console (~> 0.5)
|
43
|
+
rspec (3.11.0)
|
44
|
+
rspec-core (~> 3.11.0)
|
45
|
+
rspec-expectations (~> 3.11.0)
|
46
|
+
rspec-mocks (~> 3.11.0)
|
47
|
+
rspec-core (3.11.0)
|
48
|
+
rspec-support (~> 3.11.0)
|
49
|
+
rspec-expectations (3.11.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.11.0)
|
52
|
+
rspec-mocks (3.11.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.11.0)
|
55
|
+
rspec-support (3.11.0)
|
56
|
+
thor (1.2.1)
|
57
|
+
thread_safe (0.3.6)
|
58
|
+
tzinfo (1.2.10)
|
59
|
+
thread_safe (~> 0.1)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
activerecord (~> 5.0.0)
|
66
|
+
activerecord-nulldb-adapter
|
67
|
+
appraisal
|
68
|
+
debug
|
69
|
+
rake
|
70
|
+
rspec
|
71
|
+
stator!
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.3.16
|
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
stator (0.
|
4
|
+
stator (0.9.0.beta)
|
5
5
|
activerecord
|
6
|
+
activesupport
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -25,11 +26,19 @@ GEM
|
|
25
26
|
rake
|
26
27
|
thor (>= 0.14.0)
|
27
28
|
concurrent-ruby (1.1.10)
|
29
|
+
debug (1.6.1)
|
30
|
+
irb (>= 1.3.6)
|
31
|
+
reline (>= 0.3.1)
|
28
32
|
diff-lcs (1.5.0)
|
29
33
|
i18n (1.12.0)
|
30
34
|
concurrent-ruby (~> 1.0)
|
35
|
+
io-console (0.5.11)
|
36
|
+
irb (1.4.1)
|
37
|
+
reline (>= 0.3.0)
|
31
38
|
minitest (5.16.2)
|
32
39
|
rake (13.0.6)
|
40
|
+
reline (0.3.1)
|
41
|
+
io-console (~> 0.5)
|
33
42
|
rspec (3.11.0)
|
34
43
|
rspec-core (~> 3.11.0)
|
35
44
|
rspec-expectations (~> 3.11.0)
|
@@ -56,9 +65,10 @@ DEPENDENCIES
|
|
56
65
|
activerecord (~> 6.0.0)
|
57
66
|
activerecord-nulldb-adapter
|
58
67
|
appraisal
|
68
|
+
debug
|
59
69
|
rake
|
60
70
|
rspec
|
61
71
|
stator!
|
62
72
|
|
63
73
|
BUNDLED WITH
|
64
|
-
2.3.
|
74
|
+
2.3.16
|
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
stator (0.
|
4
|
+
stator (0.9.0.beta)
|
5
5
|
activerecord
|
6
|
+
activesupport
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -25,11 +26,19 @@ GEM
|
|
25
26
|
rake
|
26
27
|
thor (>= 0.14.0)
|
27
28
|
concurrent-ruby (1.1.10)
|
29
|
+
debug (1.6.1)
|
30
|
+
irb (>= 1.3.6)
|
31
|
+
reline (>= 0.3.1)
|
28
32
|
diff-lcs (1.5.0)
|
29
33
|
i18n (1.12.0)
|
30
34
|
concurrent-ruby (~> 1.0)
|
35
|
+
io-console (0.5.11)
|
36
|
+
irb (1.4.1)
|
37
|
+
reline (>= 0.3.0)
|
31
38
|
minitest (5.16.2)
|
32
39
|
rake (13.0.6)
|
40
|
+
reline (0.3.1)
|
41
|
+
io-console (~> 0.5)
|
33
42
|
rspec (3.11.0)
|
34
43
|
rspec-core (~> 3.11.0)
|
35
44
|
rspec-expectations (~> 3.11.0)
|
@@ -55,9 +64,10 @@ DEPENDENCIES
|
|
55
64
|
activerecord (~> 6.1.0)
|
56
65
|
activerecord-nulldb-adapter
|
57
66
|
appraisal
|
67
|
+
debug
|
58
68
|
rake
|
59
69
|
rspec
|
60
70
|
stator!
|
61
71
|
|
62
72
|
BUNDLED WITH
|
63
|
-
2.3.
|
73
|
+
2.3.16
|
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ..
|
3
3
|
specs:
|
4
|
-
stator (0.
|
4
|
+
stator (0.9.0.beta)
|
5
5
|
activerecord
|
6
|
+
activesupport
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
@@ -24,11 +25,19 @@ GEM
|
|
24
25
|
rake
|
25
26
|
thor (>= 0.14.0)
|
26
27
|
concurrent-ruby (1.1.10)
|
28
|
+
debug (1.6.1)
|
29
|
+
irb (>= 1.3.6)
|
30
|
+
reline (>= 0.3.1)
|
27
31
|
diff-lcs (1.5.0)
|
28
32
|
i18n (1.12.0)
|
29
33
|
concurrent-ruby (~> 1.0)
|
34
|
+
io-console (0.5.11)
|
35
|
+
irb (1.4.1)
|
36
|
+
reline (>= 0.3.0)
|
30
37
|
minitest (5.16.2)
|
31
38
|
rake (13.0.6)
|
39
|
+
reline (0.3.1)
|
40
|
+
io-console (~> 0.5)
|
32
41
|
rspec (3.11.0)
|
33
42
|
rspec-core (~> 3.11.0)
|
34
43
|
rspec-expectations (~> 3.11.0)
|
@@ -53,9 +62,10 @@ DEPENDENCIES
|
|
53
62
|
activerecord (~> 7.0.0)
|
54
63
|
activerecord-nulldb-adapter
|
55
64
|
appraisal
|
65
|
+
debug
|
56
66
|
rake
|
57
67
|
rspec
|
58
68
|
stator!
|
59
69
|
|
60
70
|
BUNDLED WITH
|
61
|
-
2.3.
|
71
|
+
2.3.16
|
data/lib/stator/alias.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Stator
|
2
4
|
class Alias
|
5
|
+
attr_reader :machine, :name, :namespace, :attr_name, :states, :not, :opposite_args, :constant, :scope
|
3
6
|
|
4
7
|
def initialize(machine, name, options = {})
|
5
8
|
@machine = machine
|
6
9
|
@name = name
|
7
|
-
@namespace =
|
8
|
-
@full_name = [@namespace, @name].compact.join('_')
|
10
|
+
@namespace = machine.namespace
|
9
11
|
@states = []
|
10
12
|
@not = false
|
11
13
|
@opposite = nil
|
@@ -13,8 +15,12 @@ module Stator
|
|
13
15
|
@scope = options[:scope]
|
14
16
|
end
|
15
17
|
|
18
|
+
def attr_name
|
19
|
+
@attr_name ||= generate_attr_name
|
20
|
+
end
|
21
|
+
|
16
22
|
def is(*args)
|
17
|
-
@states |= args.map(&:
|
23
|
+
@states |= args.map(&:to_sym)
|
18
24
|
end
|
19
25
|
|
20
26
|
def is_not(*args)
|
@@ -22,60 +28,75 @@ module Stator
|
|
22
28
|
is(*args)
|
23
29
|
end
|
24
30
|
|
31
|
+
alias not? not
|
32
|
+
|
25
33
|
def opposite(*args)
|
26
|
-
|
34
|
+
# set the incoming args for opposite as opposite
|
35
|
+
@opposite_args = args
|
27
36
|
end
|
28
37
|
|
29
38
|
def evaluate
|
30
39
|
generate_methods
|
31
40
|
|
32
|
-
if
|
33
|
-
op = @machine.state_alias(*@opposite)
|
41
|
+
return if opposite_args.blank?
|
34
42
|
|
35
|
-
|
36
|
-
|
37
|
-
|
43
|
+
# this will generate the alias for the opposite
|
44
|
+
op = machine.state_alias(*opposite_args)
|
45
|
+
|
46
|
+
op.is(*states) if not?
|
47
|
+
op.is_not(*states) unless not?
|
38
48
|
end
|
39
49
|
|
40
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
def inverse_states
|
53
|
+
(machine.states - states).map(&:to_sym)
|
54
|
+
end
|
41
55
|
|
42
56
|
def inferred_constant_name
|
43
|
-
[
|
57
|
+
[attr_name.upcase, machine.field.to_s.pluralize.upcase].join('_')
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_attr_name
|
61
|
+
if namespace == Stator.default_namespace
|
62
|
+
name
|
63
|
+
else
|
64
|
+
[namespace, name].compact.join('_').to_sym
|
65
|
+
end
|
44
66
|
end
|
45
67
|
|
46
68
|
def generate_methods
|
69
|
+
expected_states = (not? ? inverse_states : states)
|
47
70
|
|
48
|
-
|
71
|
+
if scope
|
72
|
+
name = (scope == true ? attr_name : scope)
|
49
73
|
|
50
|
-
|
51
|
-
|
52
|
-
@machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
|
53
|
-
scope #{name.inspect}, lambda {
|
54
|
-
where(_stator(#{@namespace.inspect}).field => #{(@not ? not_states : @states).inspect})
|
55
|
-
}
|
74
|
+
machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
|
75
|
+
scope :#{name}, -> { where(_stator(#{namespace.inspect}).field => #{expected_states}) }
|
56
76
|
EV
|
57
77
|
end
|
58
78
|
|
59
|
-
if
|
60
|
-
name =
|
61
|
-
|
62
|
-
|
63
|
-
|
79
|
+
if constant
|
80
|
+
name = (constant == true ? inferred_constant_name : constant.to_s.upcase)
|
81
|
+
|
82
|
+
if not?
|
83
|
+
machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
|
84
|
+
#{name} = #{inverse_states}.freeze
|
64
85
|
EV
|
65
86
|
else
|
66
|
-
|
67
|
-
#{name} = #{
|
87
|
+
machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
|
88
|
+
#{name} = #{states}.freeze
|
68
89
|
EV
|
69
90
|
end
|
70
91
|
end
|
71
92
|
|
72
|
-
|
73
|
-
def #{
|
74
|
-
integration =
|
75
|
-
|
93
|
+
machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
|
94
|
+
def #{attr_name}?
|
95
|
+
integration = _stator_integration(:#{namespace})
|
96
|
+
|
97
|
+
#{expected_states}.include?(integration.state.to_sym)
|
76
98
|
end
|
77
99
|
EV
|
78
100
|
end
|
79
|
-
|
80
101
|
end
|
81
102
|
end
|