stator 0.5.0 → 0.9.0.beta

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: ed80bf93083d69f85339e493f1e2512344590bb769481bf35ae56a2d84697805
4
- data.tar.gz: fb06422dde19bcd74c2cf9c3dfb2f9dfa506ca922c3a923919d96490eadacc0f
3
+ metadata.gz: 11dfad97bef44bb60c060b086dce2f327f2fca47d309510337533f31f62e105f
4
+ data.tar.gz: 578888569b569b4e35c7c180ed3ddfe96ea4547f296394c2c81fbc44bee72105
5
5
  SHA512:
6
- metadata.gz: 129800a5b02be2a8b2ac2fdc4d038cf7b51f147ad5090731e6de2a272312d01abe58569d462ddf2b51ebc397c3af5fe903ff1aa84588e234a8088a2694b9296d
7
- data.tar.gz: 9d36dfc17db1d95e72843c18f4ee7f6392ebfbf3c5bcc3950e2bdd091808a9df2e646e1d5ee6d3532bcbf40772958eef8af2c4cd6e7ae0c1baab8982ee246818
6
+ metadata.gz: 959635a8a2eebce12473a7f79844e25de1038fe3a1e692fa97e5d1edc430778a3148a4a7b6ca2e488f248c318a19d74fb69c489c28928ff44731c0e3e8319823
7
+ data.tar.gz: a13fa8a216bc2fd590d1abea7be2eab258a5e29b58c0017314a083938b5c6f6f0acebf3179b5c4cf7b122dbc2a62ba1342bdc0937fed82365ad2b23d49ce3201
@@ -3,15 +3,21 @@ on:
3
3
  pull_request:
4
4
  push:
5
5
  branches:
6
- - main
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
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .envrc
data/Appraisals CHANGED
@@ -1,3 +1,7 @@
1
+ appraise "activerecord-5" do
2
+ gem "activerecord", "~> 5.0.0"
3
+ end
4
+
1
5
  appraise "activerecord-5.1" do
2
6
  gem "activerecord", "~> 5.1.0"
3
7
  end
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gem 'activerecord', '~> 5.2.8'
5
5
  gemspec
6
6
 
7
7
  gem 'appraisal'
8
+ gem 'debug'
8
9
  gem 'activerecord-nulldb-adapter'
9
10
  gem 'rake'
10
11
  gem 'rspec'
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.1.0"
6
6
  gem "appraisal"
7
+ gem "debug"
7
8
  gem "activerecord-nulldb-adapter"
8
9
  gem "rake"
9
10
  gem "rspec"
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stator (0.5.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.25
74
+ 2.3.16
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 5.2.0"
6
6
  gem "appraisal"
7
+ gem "debug"
7
8
  gem "activerecord-nulldb-adapter"
8
9
  gem "rake"
9
10
  gem "rspec"
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stator (0.5.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.25
74
+ 2.3.16
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0.0"
6
+ gem "appraisal"
7
+ gem "debug"
8
+ gem "activerecord-nulldb-adapter"
9
+ gem "rake"
10
+ gem "rspec"
11
+
12
+ gemspec path: "../"
@@ -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
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 6.0.0"
6
6
  gem "appraisal"
7
+ gem "debug"
7
8
  gem "activerecord-nulldb-adapter"
8
9
  gem "rake"
9
10
  gem "rspec"
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stator (0.5.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.25
74
+ 2.3.16
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 6.1.0"
6
6
  gem "appraisal"
7
+ gem "debug"
7
8
  gem "activerecord-nulldb-adapter"
8
9
  gem "rake"
9
10
  gem "rspec"
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stator (0.5.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.25
73
+ 2.3.16
@@ -4,6 +4,7 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "activerecord", "~> 7.0.0"
6
6
  gem "appraisal"
7
+ gem "debug"
7
8
  gem "activerecord-nulldb-adapter"
8
9
  gem "rake"
9
10
  gem "rspec"
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- stator (0.5.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.25
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 = @machine.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(&:to_s)
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
- @opposite = args
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 @opposite
33
- op = @machine.state_alias(*@opposite)
41
+ return if opposite_args.blank?
34
42
 
35
- op.is(*@states) if @not
36
- op.is_not(*@states) if !@not
37
- end
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
- protected
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
- [@full_name.upcase, @machine.field.to_s.pluralize.upcase].join('_')
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
- not_states = (@machine.states - @states)
71
+ if scope
72
+ name = (scope == true ? attr_name : scope)
49
73
 
50
- if @scope
51
- name = @scope == true ? @full_name : @scope
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 @constant
60
- name = @constant == true ? inferred_constant_name : @constant.to_s.upcase
61
- if @not
62
- @machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
63
- #{name} = #{not_states.inspect}.freeze
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
- @machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
67
- #{name} = #{@states.inspect}.freeze
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
- @machine.klass.class_eval <<-EV, __FILE__, __LINE__ + 1
73
- def #{@full_name}?
74
- integration = _stator(#{@namespace.inspect}).integration(self)
75
- #{(@not ? not_states : @states).inspect}.include?(integration.state)
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