stator 0.9.0.beta → 0.9.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.
@@ -1,207 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class User < ActiveRecord::Base
4
- include Stator::Model
5
-
6
- before_save :set_tagged_at
7
-
8
- stator track: true, initial: :pending do
9
-
10
- transition :activate do
11
- from :pending, :semiactivated
12
- to :activated
13
- end
14
-
15
- transition :deactivate do
16
- from any
17
- to :deactivated
18
-
19
- conditional do |condition|
20
- before_save :set_deactivated, if: condition
21
- end
22
- end
23
-
24
- transition :semiactivate do
25
- from :pending
26
- to :semiactivated
27
-
28
- conditional do |condition|
29
- validate :check_email_validity, if: condition
30
- end
31
- end
32
-
33
- transition :hyperactivate do
34
- from :activated
35
- to :hyperactivated
36
- end
37
-
38
- conditional :semiactivated, :activated do |condition|
39
- validate :check_email_presence, if: condition
40
- end
41
-
42
- state_alias :active, constant: true, scope: true do
43
- is :activated, :hyperactivated
44
- opposite :inactive, constant: true, scope: true
45
- end
46
-
47
- state_alias :luke_warm, constant: :luke_warmers, scope: :luke_warmers do
48
- is :semiactivated
49
- opposite :iced_tea
50
- end
51
- end
52
-
53
- validate :email_is_right_length
54
-
55
- protected
56
-
57
- def check_email_presence
58
- if email.nil? || email.empty?
59
- errors.add(:email, 'needs to be present')
60
- return false
61
- end
62
-
63
- true
64
- end
65
-
66
- def check_email_validity
67
- unless /example\.com$/.match?(email.to_s)
68
- errors.add(:email, 'format needs to be example.com')
69
- return false
70
- end
71
-
72
- true
73
- end
74
-
75
- def email_is_right_length
76
- unless email.to_s.length == 'four@example.com'.length
77
- errors.add(:email, 'needs to be the right length')
78
- return false
79
- end
80
-
81
- true
82
- end
83
-
84
- def set_deactivated
85
- self.activated = false
86
- true
87
- end
88
-
89
- def set_tagged_at
90
- self.tagged_at = semiactivated_state_at
91
- end
92
- end
93
-
94
- class Animal < ActiveRecord::Base
95
- include Stator::Model
96
-
97
- # initial state = unborn
98
- stator field: :status, track: true do
99
- transition :birth do
100
- from :unborn
101
- to :born
102
- end
103
-
104
- state :grown_up
105
- end
106
- end
107
-
108
- class Zoo < ActiveRecord::Base
109
- include Stator::Model
110
-
111
- # initial state = closed
112
- stator do
113
- transition :open do
114
- from :closed
115
- to :opened
116
- end
117
-
118
- transition :close do
119
- from :opened
120
- to :closed
121
- end
122
-
123
- conditional :opened do |c|
124
- validate :validate_lights_are_on, if: c
125
- end
126
- end
127
-
128
- protected
129
-
130
- def validate_lights_are_on
131
- true
132
- end
133
- end
134
-
135
- class ZooKeeper < ActiveRecord::Base
136
- include Stator::Model
137
-
138
- stator namespace: 'employment', field: 'employment_state', track: true do
139
- transition :hire do
140
- from nil, :fired
141
- to :hired
142
- end
143
-
144
- transition :fire do
145
- from :hired
146
- to :fired
147
- end
148
- end
149
-
150
- stator namespace: 'working', field: 'working_state', track: false do
151
- transition :start do
152
- from nil, :ended
153
- to :started
154
- end
155
-
156
- transition :end do
157
- from :started
158
- to :ended
159
- end
160
- end
161
- end
162
-
163
- class Farm < ActiveRecord::Base
164
- include Stator::Model
165
-
166
- # initial state = dirty
167
- stator do
168
- transition :cleanup do
169
- from :dirty
170
- to :clean
171
- end
172
- end
173
-
174
- # initial state = dirty
175
- stator namespace: 'house', field: 'house_state' do
176
- transition :cleanup do
177
- from :dirty
178
- to :clean
179
- end
180
-
181
- transition :ruin do
182
- from any
183
- to :disgusting
184
- end
185
-
186
- state_alias :cleaned do
187
- is_not :dirty, :disgusting
188
- end
189
- end
190
- end
191
-
192
- class Factory < ActiveRecord::Base
193
- include Stator::Model
194
-
195
- # initial state = nil
196
- stator do
197
- transition :construct do
198
- from nil
199
- to :constructed
200
- end
201
-
202
- transition :destruct do
203
- from :constructed
204
- to :on_the_ground
205
- end
206
- end
207
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
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'
14
- end
15
-
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'
24
- end
25
-
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'
34
- end
35
-
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
41
- end
42
-
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
49
- end
50
-
51
- create_table 'factories', force: true do |t|
52
- t.string 'name'
53
- t.string 'state'
54
- end
55
- end