stator 0.1.4 → 0.1.5
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 +33 -5
- data/lib/stator/model.rb +5 -0
- data/lib/stator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 813eb5f387c3f467935894391e29ec246d9591cf
|
4
|
+
data.tar.gz: 0c345b053ec9402ee9466225894411b7baf3d205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0f5a3887ea6ec9ccbb5085d5bacd216cb0af88c56fae7dfdccfddd6d96d97cc2b1b25ee3187c1a8dcdd8d61dd9bdf647425103041e0f8d8ecd7801f80c9bb61
|
7
|
+
data.tar.gz: 7c5c5b3995d047c798cf9f52d7dec00205a2798e4cdd5a3ae227e14448fba752d06c026c808ecff66e8b747de9de4fc2b9bba9897ede59f3b75290fd2525846e
|
data/lib/stator/integration.rb
CHANGED
@@ -77,20 +77,48 @@ module Stator
|
|
77
77
|
|
78
78
|
state_at = @record.send("#{state}_#{@machine.field}_at")
|
79
79
|
|
80
|
+
# if we've never been in the state, the answer is no
|
80
81
|
return false if state_at.nil?
|
82
|
+
|
83
|
+
# if we came into this state later in life, the answer is no
|
81
84
|
return false if state_at > t
|
82
85
|
|
83
|
-
|
86
|
+
all_states = @machine.states.reverse
|
87
|
+
|
88
|
+
# grab all the states and their timestamps that occur on or after state_at and on or before the time in question
|
89
|
+
later_states = all_states.map do |s|
|
90
|
+
|
84
91
|
next if state == s
|
92
|
+
|
85
93
|
at = @record.send("#{s}_#{@machine.field}_at")
|
86
|
-
at && at >= state_at ? at : nil
|
87
|
-
end.compact.sort[0]
|
88
94
|
|
89
|
-
|
90
|
-
|
95
|
+
next if at.nil?
|
96
|
+
next if at < state_at
|
97
|
+
next if at > t
|
98
|
+
|
99
|
+
{ state: s, at: at }
|
100
|
+
end.compact
|
101
|
+
|
102
|
+
# if there were no states on or after the state_at, the answer is yes
|
103
|
+
return true if later_states.empty?
|
104
|
+
|
105
|
+
# grab the states that were present at the lowest timestamp
|
106
|
+
later_groups = later_states.group_by{|s| s[:at] }
|
107
|
+
later_group_key = later_groups.keys.sort[0]
|
108
|
+
later_states = later_groups[later_group_key]
|
109
|
+
|
110
|
+
# if the lowest timestamp is the same as the state's timestamp, evaluate based on state index
|
111
|
+
if later_states[0][:at] == state_at
|
112
|
+
return all_states.index(state) < all_states.index(later_states[0][:state])
|
113
|
+
end
|
114
|
+
|
91
115
|
false
|
92
116
|
end
|
93
117
|
|
118
|
+
def likely_state_at(t)
|
119
|
+
@machine.states.reverse.detect{|s| in_state_at?(s,t) }
|
120
|
+
end
|
121
|
+
|
94
122
|
|
95
123
|
protected
|
96
124
|
|
data/lib/stator/model.rb
CHANGED
data/lib/stator/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|