stator 0.3.3 → 0.3.4
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 +4 -4
- data/lib/stator/integration.rb +8 -0
- data/lib/stator/machine.rb +5 -0
- data/lib/stator/model.rb +4 -0
- data/lib/stator/version.rb +1 -1
- data/spec/model_spec.rb +42 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d680c518e970462c590c98580c2d53fbde45bfe7a6caeecdcf9cc061986a8a8
|
4
|
+
data.tar.gz: 25ac4b8cd95b28b07f1335d58ce5adb5a2dcf059f0c8e2f4b555de7aa7465387
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33221bc724169bb503c83c6ae72da5acf009f63ce37e4d366ebf4b0668f8c93735fed301159d7ef344af27793cb55934f9e92e21a6e16841cc0c6105f39ea6ef
|
7
|
+
data.tar.gz: 23036f52c40f2f10818f0b03b530a754fcd01c71f022c7ff0d863c6981085b6b89c2777e3eff48545627b2dc8e73fae73fe865c5a4d8f91f0d898f6393e5ec7a
|
data/lib/stator/integration.rb
CHANGED
@@ -31,6 +31,14 @@ module Stator
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def state_by?(state, time)
|
35
|
+
field_name = "#{state}_#{@machine.field}_at"
|
36
|
+
return false unless @record.respond_to?(field_name)
|
37
|
+
return false if @record.send(field_name).nil?
|
38
|
+
return true if time.nil?
|
39
|
+
@record.send(field_name) <= time
|
40
|
+
end
|
41
|
+
|
34
42
|
def state_changed?(use_previous = false)
|
35
43
|
if use_previous
|
36
44
|
!!@record.previous_changes[@machine.field.to_s]
|
data/lib/stator/machine.rb
CHANGED
@@ -117,6 +117,11 @@ module Stator
|
|
117
117
|
integration = self._stator(#{@namespace.inspect}).integration(self)
|
118
118
|
integration.state == #{state.to_s.inspect}
|
119
119
|
end
|
120
|
+
|
121
|
+
def #{method_name}_by?(time)
|
122
|
+
integration = self._stator(#{@namespace.inspect}).integration(self)
|
123
|
+
integration.state_by?(#{state.to_s.inspect}, time)
|
124
|
+
end
|
120
125
|
EV
|
121
126
|
end
|
122
127
|
end
|
data/lib/stator/model.rb
CHANGED
data/lib/stator/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -305,6 +305,48 @@ describe Stator::Model do
|
|
305
305
|
z.working_end!
|
306
306
|
z.ended_working_state_at.should be_nil
|
307
307
|
end
|
308
|
+
|
309
|
+
describe "#state_by?" do
|
310
|
+
it "should be true when the transition is earlier" do
|
311
|
+
t = Time.now
|
312
|
+
u = User.create!( email: "doug@example.com", activated_state_at: t)
|
313
|
+
u.state_by?(:activated, Time.at(t.to_i + 1)).should be true
|
314
|
+
u.activated_by?(Time.at(t.to_i + 1)).should be true
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should be true when the transition is at the same time" do
|
318
|
+
t = Time.now
|
319
|
+
u = User.create!( email: "doug@example.com", activated_state_at: t)
|
320
|
+
u.state_by?(:activated, t).should be true
|
321
|
+
u.activated_by?(t).should be true
|
322
|
+
end
|
323
|
+
|
324
|
+
it "should be false when the transition is later" do
|
325
|
+
t = Time.now
|
326
|
+
u = User.create!( email: "doug@example.com", activated_state_at: t)
|
327
|
+
u.state_by?(:activated, Time.at(t.to_i - 1)).should be false
|
328
|
+
u.activated_by?(Time.at(t.to_i - 1)).should be false
|
329
|
+
end
|
330
|
+
|
331
|
+
it "should be false when the transition is nil" do
|
332
|
+
t = Time.now
|
333
|
+
u = User.create!( email: "doug@example.com", activated_state_at: nil)
|
334
|
+
u.state_by?(:activated, t).should be false
|
335
|
+
u.activated_by?(t).should be false
|
336
|
+
end
|
337
|
+
|
338
|
+
it "should be true when the transition is not nil and the time is nil" do
|
339
|
+
u = User.create!( email: "doug@example.com", activated_state_at: Time.now)
|
340
|
+
u.state_by?(:activated, nil).should be true
|
341
|
+
u.activated_by?(nil).should be true
|
342
|
+
end
|
343
|
+
|
344
|
+
it "should be false when both are nil" do
|
345
|
+
u = User.create!(email: "doug@example.com", activated_state_at: nil)
|
346
|
+
u.state_by?(:activated, nil).should be false
|
347
|
+
u.activated_by?(nil).should be false
|
348
|
+
end
|
349
|
+
end
|
308
350
|
end
|
309
351
|
|
310
352
|
describe "aliasing" do
|
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.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|