state_of_the_nation 1.1.6 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc3cdbd88385c581951562d576585cc78ff3528de59b908b280ad331c4794bc4
4
- data.tar.gz: 4a41b1f65f1d1e517568deb529e1fdfaaae033a561d5b2d8b660a49588590c64
3
+ metadata.gz: 36525e79ab3fded0f8985975e73eaac75b0d535b530a1261bb8208d2e984b330
4
+ data.tar.gz: 2da7c70d311533899e611d3118f048763c753f4560880483b7bb4e27552e172f
5
5
  SHA512:
6
- metadata.gz: 35dba604ed379b09913369ac0f59b14593c5c6fd40f7fa999733235a71b8ab5da41e9fb6a03e635fc04ab83535eb7699303723c3036cadac9c206208e2873a0c
7
- data.tar.gz: 5a44d3263e9cafec224645750ae87e7e78faa7d85e27a5dbcc4e6a318658a1bdfec3da2554003fe6de712582a282341b655d2cbb8096385babf82603a2cad123
6
+ metadata.gz: 48703e6f70341a407ffd5d2804e09681b8ac841c48776aba500a6e0f32348300c4fdfa15d985be3a38b2dc22e41c8687d92dab0f0d94f7b244a5f23d80be335e
7
+ data.tar.gz: e3f1d4895d066f56ad5aa2d23aff060c71787e005c7c7609e8182af7b5cd3e2ba2840c986381fe68a5e9982c0ed88cf044f4b0522ef19b82974751ef48764a79
data/.circleci/config.yml CHANGED
@@ -5,7 +5,7 @@ jobs:
5
5
  RAILS_ENV: test
6
6
 
7
7
  docker:
8
- - image: circleci/ruby:2.5.5
8
+ - image: circleci/ruby:2.7.5
9
9
 
10
10
  steps:
11
11
  - checkout
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.5
1
+ 2.7.5
@@ -1,3 +1,3 @@
1
1
  module StateOfTheNation
2
- VERSION = "1.1.6"
2
+ VERSION = "2.0.1"
3
3
  end
@@ -27,12 +27,12 @@ module StateOfTheNation
27
27
  @finish_key = finish_key
28
28
 
29
29
  define_method "active?" do |time = Time.now.utc|
30
- (finish.blank? || round_if_should(finish) > round_if_should(time)) && round_if_should(start) <= round_if_should(time)
30
+ (finish.blank? || finish > time) && start <= time
31
31
  end
32
32
 
33
33
  define_method "active_in_interval?" do |interval_start, interval_end|
34
- record_start = round_if_should(start)
35
- record_end = round_if_should(finish)
34
+ record_start = start
35
+ record_end = finish
36
36
  if ignore_empty && record_start == record_end
37
37
  false
38
38
  elsif interval_start.nil? && interval_end.nil?
@@ -51,28 +51,10 @@ module StateOfTheNation
51
51
  end
52
52
 
53
53
  scope :active, lambda { |time = Time.now.utc|
54
- where(QueryString.query_for(:active_scope, self), round_if_should(time), round_if_should(time))
54
+ where(QueryString.query_for(:active_scope, self), time, time)
55
55
  }
56
56
  end
57
57
 
58
- private def round_if_should(time)
59
- return time if !should_round_timestamps?
60
- time.respond_to?(:round) ? time.round : time
61
- end
62
-
63
- private def should_round_timestamps?
64
- # MySQL datetime fields do not support millisecond resolution while
65
- # PostgreSQL's do. To prevent issues with near identical timestamps not
66
- # comparing as expected in .active? methods we'll choose the resolution
67
- # appropriate for the database adapter backing the model.
68
- case self.connection.adapter_name
69
- when /PostgreSQL/
70
- false
71
- else
72
- true
73
- end
74
- end
75
-
76
58
  self
77
59
  end
78
60
 
@@ -103,8 +85,10 @@ module StateOfTheNation
103
85
  private
104
86
 
105
87
  def add_child_methods(plural:, single:, with_identity_cache:)
106
- child_class = self.reflect_on_association(plural).klass
107
- name = self.name.demodulize.underscore.to_sym
88
+ reflection = self.reflect_on_association(plural)
89
+ name = reflection.inverse_of&.name || self.name.demodulize.underscore.to_sym
90
+
91
+ child_class = reflection.klass
108
92
  child_class.instance_variable_set(:@parent_association, name)
109
93
  child_class.instance_variable_set(:@prevent_multiple_active, single)
110
94
 
@@ -163,12 +147,12 @@ module StateOfTheNation
163
147
 
164
148
  def start
165
149
  return unless start_key.present?
166
- return round_if_should(self.send(start_key) || Time.now.utc)
150
+ return self.send(start_key) || Time.now.utc
167
151
  end
168
152
 
169
153
  def finish
170
154
  return unless finish_key.present?
171
- round_if_should(self.send(finish_key))
155
+ self.send(finish_key)
172
156
  end
173
157
 
174
158
  def bad_configuration?
@@ -196,13 +180,4 @@ module StateOfTheNation
196
180
  def ignore_empty
197
181
  self.class.ignore_empty
198
182
  end
199
-
200
- def should_round_timestamps?
201
- self.class.send(:should_round_timestamps?)
202
- end
203
-
204
- def round_if_should(time)
205
- return time if time.nil?
206
- self.class.send(:round_if_should, time)
207
- end
208
183
  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.6
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick O'Doherty
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-03-12 00:00:00.000000000 Z
12
+ date: 2023-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -223,8 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  - !ruby/object:Gem::Version
224
224
  version: '0'
225
225
  requirements: []
226
- rubyforge_project:
227
- rubygems_version: 2.7.6.2
226
+ rubygems_version: 3.1.6
228
227
  signing_key:
229
228
  specification_version: 4
230
229
  summary: An easy way to model state that changes over time with ActiveRecord