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.
@@ -1,19 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class User < ActiveRecord::Base
2
- extend Stator::Model
4
+ include Stator::Model
3
5
 
4
6
  before_save :set_tagged_at
5
7
 
6
- attr_reader :activation_notification_published
7
-
8
8
  stator track: true, initial: :pending do
9
9
 
10
10
  transition :activate do
11
11
  from :pending, :semiactivated
12
12
  to :activated
13
-
14
- conditional(use_previous: true) do |condition|
15
- after_save :publish_activation_notification, :if => condition
16
- end
17
13
  end
18
14
 
19
15
  transition :deactivate do
@@ -21,7 +17,7 @@ class User < ActiveRecord::Base
21
17
  to :deactivated
22
18
 
23
19
  conditional do |condition|
24
- before_save :set_deactivated, :if => condition
20
+ before_save :set_deactivated, if: condition
25
21
  end
26
22
  end
27
23
 
@@ -30,7 +26,7 @@ class User < ActiveRecord::Base
30
26
  to :semiactivated
31
27
 
32
28
  conditional do |condition|
33
- validate :check_email_validity, :if => condition
29
+ validate :check_email_validity, if: condition
34
30
  end
35
31
  end
36
32
 
@@ -40,19 +36,18 @@ class User < ActiveRecord::Base
40
36
  end
41
37
 
42
38
  conditional :semiactivated, :activated do |condition|
43
- validate :check_email_presence, :if => condition
39
+ validate :check_email_presence, if: condition
44
40
  end
45
41
 
46
- state_alias :active, :constant => true, :scope => true do
42
+ state_alias :active, constant: true, scope: true do
47
43
  is :activated, :hyperactivated
48
- opposite :inactive, :constant => true, :scope => true
44
+ opposite :inactive, constant: true, scope: true
49
45
  end
50
46
 
51
- state_alias :luke_warm, :constant => :luke_warmers, :scope => :luke_warmers do
47
+ state_alias :luke_warm, constant: :luke_warmers, scope: :luke_warmers do
52
48
  is :semiactivated
53
49
  opposite :iced_tea
54
50
  end
55
-
56
51
  end
57
52
 
58
53
  validate :email_is_right_length
@@ -60,8 +55,8 @@ class User < ActiveRecord::Base
60
55
  protected
61
56
 
62
57
  def check_email_presence
63
- unless self.email.present?
64
- self.errors.add(:email, 'needs to be present')
58
+ if email.nil? || email.empty?
59
+ errors.add(:email, 'needs to be present')
65
60
  return false
66
61
  end
67
62
 
@@ -69,8 +64,8 @@ class User < ActiveRecord::Base
69
64
  end
70
65
 
71
66
  def check_email_validity
72
- unless self.email.to_s =~ /example\.com$/
73
- self.errors.add(:email, 'format needs to be example.com')
67
+ unless /example\.com$/.match?(email.to_s)
68
+ errors.add(:email, 'format needs to be example.com')
74
69
  return false
75
70
  end
76
71
 
@@ -78,8 +73,8 @@ class User < ActiveRecord::Base
78
73
  end
79
74
 
80
75
  def email_is_right_length
81
- unless self.email.to_s.length == 'four@example.com'.length
82
- self.errors.add(:email, 'needs to be the right length')
76
+ unless email.to_s.length == 'four@example.com'.length
77
+ errors.add(:email, 'needs to be the right length')
83
78
  return false
84
79
  end
85
80
 
@@ -92,39 +87,29 @@ class User < ActiveRecord::Base
92
87
  end
93
88
 
94
89
  def set_tagged_at
95
- self.tagged_at = self.semiactivated_state_at
90
+ self.tagged_at = semiactivated_state_at
96
91
  end
97
-
98
- private
99
-
100
- def publish_activation_notification
101
- @activation_notification_published = true
102
- end
103
-
104
92
  end
105
93
 
106
94
  class Animal < ActiveRecord::Base
107
- extend Stator::Model
95
+ include Stator::Model
108
96
 
109
97
  # initial state = unborn
110
- stator :field => :status, :helpers => true, :track => true do
111
-
98
+ stator field: :status, track: true do
112
99
  transition :birth do
113
100
  from :unborn
114
101
  to :born
115
102
  end
116
103
 
117
104
  state :grown_up
118
-
119
105
  end
120
106
  end
121
107
 
122
108
  class Zoo < ActiveRecord::Base
123
- extend Stator::Model
109
+ include Stator::Model
124
110
 
125
111
  # initial state = closed
126
112
  stator do
127
-
128
113
  transition :open do
129
114
  from :closed
130
115
  to :opened
@@ -136,7 +121,7 @@ class Zoo < ActiveRecord::Base
136
121
  end
137
122
 
138
123
  conditional :opened do |c|
139
- validate :validate_lights_are_on, :if => c
124
+ validate :validate_lights_are_on, if: c
140
125
  end
141
126
  end
142
127
 
@@ -148,7 +133,7 @@ class Zoo < ActiveRecord::Base
148
133
  end
149
134
 
150
135
  class ZooKeeper < ActiveRecord::Base
151
- extend Stator::Model
136
+ include Stator::Model
152
137
 
153
138
  stator namespace: 'employment', field: 'employment_state', track: true do
154
139
  transition :hire do
@@ -176,20 +161,18 @@ class ZooKeeper < ActiveRecord::Base
176
161
  end
177
162
 
178
163
  class Farm < ActiveRecord::Base
179
- extend Stator::Model
164
+ include Stator::Model
180
165
 
181
166
  # initial state = dirty
182
167
  stator do
183
168
  transition :cleanup do
184
- from :dirty
185
- to :clean
169
+ from :dirty
170
+ to :clean
186
171
  end
187
172
  end
188
173
 
189
-
190
174
  # initial state = dirty
191
- stator :field => 'house_state', :namespace => 'house' do
192
-
175
+ stator namespace: 'house', field: 'house_state' do
193
176
  transition :cleanup do
194
177
  from :dirty
195
178
  to :clean
@@ -204,11 +187,10 @@ class Farm < ActiveRecord::Base
204
187
  is_not :dirty, :disgusting
205
188
  end
206
189
  end
207
-
208
190
  end
209
191
 
210
192
  class Factory < ActiveRecord::Base
211
- extend Stator::Model
193
+ include Stator::Model
212
194
 
213
195
  # initial state = nil
214
196
  stator do
@@ -222,5 +204,4 @@ class Factory < ActiveRecord::Base
222
204
  to :on_the_ground
223
205
  end
224
206
  end
225
-
226
207
  end
@@ -1,55 +1,55 @@
1
- ActiveRecord::Schema.define(:version => 20130628161227) do
1
+ # frozen_string_literal: true
2
2
 
3
- create_table "users", :force => true do |t|
4
- t.string "name"
5
- t.string "email"
6
- t.datetime "tagged_at"
7
- t.string "state", :default => 'pending'
8
- t.boolean "activated", :default => true
9
- t.datetime "created_at", :null => false
10
- t.datetime "updated_at", :null => false
11
- t.datetime "semiactivated_state_at"
12
- t.datetime "activated_state_at"
3
+ ActiveRecord::Schema.define(version: 20_130_628_161_227) do
4
+ create_table 'users', force: true do |t|
5
+ t.string 'name'
6
+ t.string 'email'
7
+ t.datetime 'tagged_at'
8
+ t.string 'state', default: 'pending'
9
+ t.boolean 'activated', default: true
10
+ t.datetime 'created_at', null: false
11
+ t.datetime 'updated_at', null: false
12
+ t.datetime 'semiactivated_state_at'
13
+ t.datetime 'activated_state_at'
13
14
  end
14
15
 
15
- create_table "animals", :force => true do |t|
16
- t.string "name"
17
- t.string "status", :default => 'unborn'
18
- t.datetime "created_at", :null => false
19
- t.datetime "updated_at", :null => false
20
- t.datetime "status_changed_at"
21
- t.datetime "unborn_status_at"
22
- t.datetime "born_status_at"
16
+ create_table 'animals', force: true do |t|
17
+ t.string 'name'
18
+ t.string 'status', default: 'unborn'
19
+ t.datetime 'created_at', null: false
20
+ t.datetime 'updated_at', null: false
21
+ t.datetime 'status_changed_at'
22
+ t.datetime 'unborn_status_at'
23
+ t.datetime 'born_status_at'
23
24
  end
24
25
 
25
- create_table "zoo_keepers", :force => true do |t|
26
- t.string "name"
27
- t.string "employment_state", :default => 'hired'
28
- t.datetime "hired_employment_state_at"
29
- t.datetime "fired_employment_state_at"
30
- t.string "working_state"
31
- t.datetime "started_working_state_at"
32
- t.datetime "ended_working_state_at"
26
+ create_table 'zoo_keepers', force: true do |t|
27
+ t.string 'name'
28
+ t.string 'employment_state', default: 'hired'
29
+ t.datetime 'hired_employment_state_at'
30
+ t.datetime 'fired_employment_state_at'
31
+ t.string 'working_state'
32
+ t.datetime 'started_working_state_at'
33
+ t.datetime 'ended_working_state_at'
33
34
  end
34
35
 
35
- create_table "zoos", :force => true do |t|
36
- t.string "name"
37
- t.string "state", :default => 'closed'
38
- t.datetime "created_at", :null => false
39
- t.datetime "updated_at", :null => false
36
+ create_table 'zoos', force: true do |t|
37
+ t.string 'name'
38
+ t.string 'state', default: 'closed'
39
+ t.datetime 'created_at', null: false
40
+ t.datetime 'updated_at', null: false
40
41
  end
41
42
 
42
- create_table "farms", :force => true do |t|
43
- t.string "name"
44
- t.string "state", :default => 'dirty'
45
- t.string "house_state", :default => 'dirty'
46
- t.datetime "created_at", :null => false
47
- t.datetime "updated_at", :null => false
43
+ create_table 'farms', force: true do |t|
44
+ t.string 'name'
45
+ t.string 'state', default: 'dirty'
46
+ t.string 'house_state', default: 'dirty'
47
+ t.datetime 'created_at', null: false
48
+ t.datetime 'updated_at', null: false
48
49
  end
49
50
 
50
- create_table "factories", :force => true do |t|
51
- t.string "name"
52
- t.string "state"
51
+ create_table 'factories', force: true do |t|
52
+ t.string 'name'
53
+ t.string 'state'
53
54
  end
54
-
55
55
  end
data/stator.gemspec CHANGED
@@ -18,5 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency 'activerecord'
21
- # gem.add_development_dependency "appraisal"
21
+ gem.add_dependency 'activesupport'
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.9.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-16 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  description: The simplest of ActiveRecord state machines. Intended to be lightweight
28
42
  and minimalistic.
29
43
  email:
@@ -46,6 +60,8 @@ files:
46
60
  - gemfiles/activerecord_5.1.gemfile.lock
47
61
  - gemfiles/activerecord_5.2.gemfile
48
62
  - gemfiles/activerecord_5.2.gemfile.lock
63
+ - gemfiles/activerecord_5.gemfile
64
+ - gemfiles/activerecord_5.gemfile.lock
49
65
  - gemfiles/activerecord_6.0.gemfile
50
66
  - gemfiles/activerecord_6.0.gemfile.lock
51
67
  - gemfiles/activerecord_6.1.gemfile
@@ -78,11 +94,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
94
  version: '0'
79
95
  required_rubygems_version: !ruby/object:Gem::Requirement
80
96
  requirements:
81
- - - ">="
97
+ - - ">"
82
98
  - !ruby/object:Gem::Version
83
- version: '0'
99
+ version: 1.3.1
84
100
  requirements: []
85
- rubygems_version: 3.3.23
101
+ rubygems_version: 3.1.6
86
102
  signing_key:
87
103
  specification_version: 4
88
104
  summary: The simplest of ActiveRecord state machines