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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f860e2aab34bc7885c2de966a79665080b07179e
4
- data.tar.gz: 349d751236999d5bc792d24a8f1ebc8b4cdace48
3
+ metadata.gz: c3a33b2524ff4366459b1b2acfa2d99bd64e4577
4
+ data.tar.gz: 3e2391951eeeffd3c09c6c2a5d22801df27454d3
5
5
  SHA512:
6
- metadata.gz: 66d9caa5d36028657ef95c22e2eea1083d0f7750735c6763fca06e9fbd1143c2757a2dc30ae2950e89932d20e16f66b488ed787abc3fef1be028ca0c02689850
7
- data.tar.gz: e68a543d34ee71d55167a9e1db1a7857a916194f9349fcbc21f5a7615d404458b48814cec0df528459b3ca11eb0dab15e89e3fed940af4409da077abdfc228c8
6
+ metadata.gz: 7fa8945c79a97b3b6a97191d3f8adeb19ced82cfe653d6088030e5ba2301fa84d8a887cfa49590e758ae02f7d4d920163f638196aa09858285578a6881c672d1
7
+ data.tar.gz: d36835a5772b71bbc12fdb713cd91944d0f786174c2b04b13ec76787a6219731c754331bd79c9e9f98b8b9cf502d9e8fba6e442e44aa08c679fe2d2e1c3bf48c
@@ -1,3 +1,3 @@
1
1
  module StateOfTheNation
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -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
- time = should_round_timestamps? ? time.round : time
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 { |t = Time.now.utc|
32
- where(QueryString.query_for(:active_scope, self), t, t)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_of_the_nation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick O'Doherty