stator 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4db54f443ba466ae3fc6f79857816b8719e0cbacf0615f8c014ae0c71c32e81
4
- data.tar.gz: 53d72d27aafa1a340c02d2d5459235488bf5e12df9198312ffe1d5121fc24912
3
+ metadata.gz: 3d680c518e970462c590c98580c2d53fbde45bfe7a6caeecdcf9cc061986a8a8
4
+ data.tar.gz: 25ac4b8cd95b28b07f1335d58ce5adb5a2dcf059f0c8e2f4b555de7aa7465387
5
5
  SHA512:
6
- metadata.gz: a2e76eb8e8bbe0e1dab6d8fbdbb6516f12cff56c26c3d10d974d4aadce08fbcabdcd49dbba710d0f904a1a04ea4c489125b18475a119de5e625a9cbb6e9406a4
7
- data.tar.gz: 0fef985f07d95f3d8801f4e3534f478feb516fea223532e1e562cc85bebdc54c09222ee0087517d4c3f396f4d094ad80a9404f7e0cb69829ffa6c5ddc40bb297
6
+ metadata.gz: 33221bc724169bb503c83c6ae72da5acf009f63ce37e4d366ebf4b0668f8c93735fed301159d7ef344af27793cb55934f9e92e21a6e16841cc0c6105f39ea6ef
7
+ data.tar.gz: 23036f52c40f2f10818f0b03b530a754fcd01c71f022c7ff0d863c6981085b6b89c2777e3eff48545627b2dc8e73fae73fe865c5a4d8f91f0d898f6393e5ec7a
@@ -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]
@@ -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
@@ -47,6 +47,10 @@ module Stator
47
47
  _integration(namespace).likely_state_at(t)
48
48
  end
49
49
 
50
+ def state_by?(state, t, namespace = '')
51
+ _integration(namespace).state_by?(state, t)
52
+ end
53
+
50
54
  protected
51
55
 
52
56
  def _stator_maybe_track_transition
@@ -4,7 +4,7 @@ module Stator
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 3
7
- PATCH = 3
7
+ PATCH = 4
8
8
  PRERELEASE = nil
9
9
 
10
10
  VERSION = [MAJOR, MINOR, PATCH, PRERELEASE].compact.join(".")
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.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-03-18 00:00:00.000000000 Z
11
+ date: 2021-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord