state_of_the_nation 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/state_of_the_nation/version.rb +1 -1
- data/lib/state_of_the_nation.rb +15 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3a33b2524ff4366459b1b2acfa2d99bd64e4577
|
4
|
+
data.tar.gz: 3e2391951eeeffd3c09c6c2a5d22801df27454d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fa8945c79a97b3b6a97191d3f8adeb19ced82cfe653d6088030e5ba2301fa84d8a887cfa49590e758ae02f7d4d920163f638196aa09858285578a6881c672d1
|
7
|
+
data.tar.gz: d36835a5772b71bbc12fdb713cd91944d0f786174c2b04b13ec76787a6219731c754331bd79c9e9f98b8b9cf502d9e8fba6e442e44aa08c679fe2d2e1c3bf48c
|
data/lib/state_of_the_nation.rb
CHANGED
@@ -24,12 +24,11 @@ module StateOfTheNation
|
|
24
24
|
@finish_key = finish_key
|
25
25
|
|
26
26
|
define_method "active?" do |time = Time.now.utc|
|
27
|
-
|
28
|
-
(finish.blank? || finish > time) && start <= time
|
27
|
+
(finish.blank? || round_if_should(finish) > round_if_should(time)) && round_if_should(start) <= round_if_should(time)
|
29
28
|
end
|
30
29
|
|
31
|
-
scope :active, lambda { |
|
32
|
-
where(QueryString.query_for(:active_scope, self),
|
30
|
+
scope :active, lambda { |time = Time.now.utc|
|
31
|
+
where(QueryString.query_for(:active_scope, self), round_if_should(time), round_if_should(time))
|
33
32
|
}
|
34
33
|
end
|
35
34
|
|
@@ -71,13 +70,17 @@ module StateOfTheNation
|
|
71
70
|
association = single ? plural.singularize : plural
|
72
71
|
|
73
72
|
define_method "active_#{association}" do |time = Time.now.utc|
|
74
|
-
time = should_round_timestamps? ? time.round : time
|
75
73
|
method_name = with_identity_cache ? "fetch_#{plural}" : plural.to_sym
|
76
74
|
collection = send(method_name).select { |r| r.send("active?", time) }
|
77
75
|
single ? collection.first : collection
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
79
|
+
def round_if_should(time)
|
80
|
+
return time.round if should_round_timestamps?
|
81
|
+
time
|
82
|
+
end
|
83
|
+
|
81
84
|
def should_round_timestamps?
|
82
85
|
# MySQL datetime fields do not support millisecond resolution while
|
83
86
|
# PostgreSQL's do. To prevent issues with near identical timestamps not
|
@@ -133,12 +136,12 @@ module StateOfTheNation
|
|
133
136
|
|
134
137
|
def start
|
135
138
|
return unless start_key.present?
|
136
|
-
self.send(start_key) || Time.now.utc
|
139
|
+
return round_if_should(self.send(start_key) || Time.now.utc)
|
137
140
|
end
|
138
141
|
|
139
142
|
def finish
|
140
143
|
return unless finish_key.present?
|
141
|
-
self.send(finish_key)
|
144
|
+
round_if_should(self.send(finish_key))
|
142
145
|
end
|
143
146
|
|
144
147
|
def bad_configuration?
|
@@ -166,4 +169,9 @@ module StateOfTheNation
|
|
166
169
|
def should_round_timestamps?
|
167
170
|
self.class.send(:should_round_timestamps?)
|
168
171
|
end
|
172
|
+
|
173
|
+
def round_if_should(time)
|
174
|
+
return time if time.nil?
|
175
|
+
self.class.send(:round_if_should, time)
|
176
|
+
end
|
169
177
|
end
|