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