tod 2.2.0 → 3.0.0

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: 5b81b1887eee62d6f7a98bf6281f16da3cffd47206925beca789a94b91c3e7c2
4
- data.tar.gz: 662b50760caef5be2bf7e41b1b59ced86ece56b8d46b10aa6fe7cd24e33cb869
3
+ metadata.gz: 8986b140f4dcc736d253b188cd5f9a46a72110f38887cd6e8ff93ecee823c438
4
+ data.tar.gz: 95d31c83abc1264946bf2ce6aa6ba6fac45dcaeca1362b76a22d54eab27f402f
5
5
  SHA512:
6
- metadata.gz: 8b97d86a5945a3f274b3674b11bd4f09add9ca409e4512ddba81c107acc8e5bc339896fa7b94a5da7d9e61bf8d579e7c866b0473dfc86ef3e6cd2b63c0174964
7
- data.tar.gz: f539df0792da43d8a45244e9ba978732d59c02ffc36406047725c7209a44e1958926647b05bdb9c7d51a5d1417d6f2f396246e9aeba63bb17b017b87756a9195
6
+ metadata.gz: 2d1c3b50deb1df502928666b38e113fb7d58b4a25c140119bac8155ad3ff3add0689cffba810b7bdd6ab1461493838873a839ac259895630210e47679ae9ef89
7
+ data.tar.gz: 98a76ddcb2b8c866f602efe1def27c236b88ffcc6bbb12812580794113dc964d5b6df1bd95b0f055a48e9e95ca4b69ccf3dea93b20f866ca72be7932596e1aaf
data/.travis.yml CHANGED
@@ -1,13 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.3
4
- - 2.2.6
5
- gemfile:
6
- - gemfiles/4.0.gemfile
7
- - gemfiles/4.1.gemfile
8
- - gemfiles/4.2.gemfile
9
- - gemfiles/5.0.gemfile
10
- matrix:
11
- include:
12
- - rvm: 2.5.1
13
- gemfile: gemfiles/5.2.gemfile
3
+ - 2.6.5
data/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
1
+ # 3.0.0 (March 6, 2021)
2
+
3
+ * Support and require Rails 6
4
+
1
5
  # 2.2.0 (October 10, 2018)
2
6
 
3
7
  * Add string formatting compatible with Rails (Tate Johnson)
4
8
  * Add ability to use ActiveRecord's attribute API (Brent Wheeldon)
9
+ * Add method for use in Rails database quoting (Ben Jackson)
5
10
 
6
11
  # 2.1.1 (April 14, 2017)
7
12
 
data/Gemfile.lock CHANGED
@@ -1,48 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tod (2.2.0)
4
+ tod (3.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (5.2.0)
10
- activesupport (= 5.2.0)
11
- activerecord (5.2.0)
12
- activemodel (= 5.2.0)
13
- activesupport (= 5.2.0)
14
- arel (>= 9.0)
15
- activesupport (5.2.0)
9
+ activemodel (6.1.3)
10
+ activesupport (= 6.1.3)
11
+ activerecord (6.1.3)
12
+ activemodel (= 6.1.3)
13
+ activesupport (= 6.1.3)
14
+ activesupport (6.1.3)
16
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (>= 0.7, < 2)
18
- minitest (~> 5.1)
19
- tzinfo (~> 1.1)
20
- arel (9.0.0)
21
- byebug (10.0.2)
22
- coderay (1.1.2)
23
- concurrent-ruby (1.0.5)
24
- i18n (1.0.1)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ zeitwerk (~> 2.3)
20
+ byebug (11.1.3)
21
+ coderay (1.1.3)
22
+ concurrent-ruby (1.1.8)
23
+ i18n (1.8.9)
25
24
  concurrent-ruby (~> 1.0)
26
- method_source (0.9.0)
27
- minitest (5.11.3)
28
- pry (0.11.3)
29
- coderay (~> 1.1.0)
30
- method_source (~> 0.9.0)
31
- pry-byebug (3.6.0)
32
- byebug (~> 10.0)
33
- pry (~> 0.10)
34
- rake (12.3.1)
35
- sqlite3 (1.3.13)
36
- thread_safe (0.3.6)
37
- tzinfo (1.2.5)
38
- thread_safe (~> 0.1)
25
+ method_source (1.0.0)
26
+ minitest (5.14.4)
27
+ pry (0.13.1)
28
+ coderay (~> 1.1)
29
+ method_source (~> 1.0)
30
+ pry-byebug (3.9.0)
31
+ byebug (~> 11.0)
32
+ pry (~> 0.13.0)
33
+ rake (13.0.3)
34
+ sqlite3 (1.4.2)
35
+ tzinfo (2.0.4)
36
+ concurrent-ruby (~> 1.0)
37
+ zeitwerk (2.4.2)
39
38
 
40
39
  PLATFORMS
41
40
  ruby
42
41
 
43
42
  DEPENDENCIES
44
- activerecord (>= 3.0.0)
45
- arel
43
+ activerecord (>= 6.0.0)
46
44
  minitest
47
45
  pry-byebug
48
46
  rake
@@ -51,4 +49,4 @@ DEPENDENCIES
51
49
  tzinfo
52
50
 
53
51
  BUNDLED WITH
54
- 1.16.3
52
+ 2.0.2
data/README.markdown CHANGED
@@ -226,32 +226,21 @@ produce an object with the correct time and time zone, pass in an
226
226
  tod.on time, Time.find_zone!("US/Mountain") # => Mon, 24 Sep 2018 08:30:00 MDT -06:00
227
227
  Date.tomorrow.at tod, Time.find_zone!("US/Mountain") # => Tue, 25 Sep 2018 08:30:00 MDT -06:00
228
228
 
229
- ActiveRecord Serializable Attribute Support
229
+ ActiveRecord Attribute Support
230
230
  =======================
231
- Tod::TimeOfDay implements a custom serialization contract for ActiveRecord serialize which allows to store Tod::TimeOfDay directly
231
+ Tod::TimeOfDay can be used as an ActiveRecord attribute to store Tod::TimeOfDay directly
232
232
  in a column of the time type.
233
233
 
234
234
  Example:
235
235
 
236
236
  ```ruby
237
237
  class Order < ActiveRecord::Base
238
- serialize :time, Tod::TimeOfDay
238
+ attribute :time, :time_only
239
239
  end
240
240
  order = Order.create(time: Tod::TimeOfDay.new(9,30))
241
241
  order.time # => 09:30:00
242
242
  ```
243
243
 
244
- By default Rails 5.1 treats database `time` values as if time zones are
245
- meaningful. Tod::TimeOfDay cannot correctly save and restore values when Rails
246
- automatically shifts values based on time zone and the normal `serialize`
247
- interface is not able to override this behavior. To correctly serialize
248
- Tod::TimeOfDay values with Rails 5.1 time zone handling must be disabled for
249
- database `time` types. This can be done with the following config:
250
-
251
- ```
252
- config.active_record.time_zone_aware_types = [:datetime]
253
- ```
254
-
255
244
  MongoDB Support
256
245
  ===============
257
246
 
@@ -294,10 +283,10 @@ Compatibility
294
283
 
295
284
  [![Build Status](https://travis-ci.org/jackc/tod.png)](https://travis-ci.org/jackc/tod)
296
285
 
297
- Tod is compatible with Ruby 1.9.3, 2.0.0, 2.1.8, and 2.2.0. It is tested against Rails 3.2, 4.0, 4.1, 4.2, 5.0.
286
+ Tod is tested against Ruby 2.6.x and Rails 6.x.
298
287
 
299
288
 
300
289
  License
301
290
  =======
302
291
 
303
- Copyright (c) 2010-2015 Jack Christensen, released under the MIT license
292
+ Copyright (c) 2010-2021 Jack Christensen, released under the MIT license
data/lib/tod/railtie.rb CHANGED
@@ -1,8 +1,11 @@
1
+ require "active_model/type"
2
+ require "active_record/type"
1
3
  require "tod/time_of_day_type"
2
4
 
3
5
  module Tod
4
6
  class Railtie < Rails::Railtie
5
- initializer "tod.register_active_record_type" do
7
+ initializer "tod.register_active_model_type" do
8
+ ActiveModel::Type.register(:time_only, Tod::TimeOfDayType)
6
9
  ActiveRecord::Type.register(:time_only, Tod::TimeOfDayType)
7
10
  end
8
11
  end
data/lib/tod/shift.rb CHANGED
@@ -33,20 +33,40 @@ module Tod
33
33
 
34
34
  # Returns true if ranges overlap, false otherwise.
35
35
  def overlaps?(other)
36
- max_seconds = TimeOfDay::NUM_SECONDS_IN_DAY
37
-
38
- # Standard case, when Shifts are on the same day
39
- a, b = [self, other].map(&:range).sort_by(&:first)
40
- op = a.exclude_end? ? :> : :>=
41
- return true if a.last.send(op, b.first)
42
-
43
- # Special cases, when Shifts span to the next day
44
- return false if (a.last < max_seconds) && (b.last < max_seconds)
45
-
46
- a = Range.new(a.first, a.last - max_seconds, a.exclude_end?) if a.last > max_seconds
47
- b = Range.new(b.first, b.last - max_seconds, b.exclude_end?) if b.last > max_seconds
48
- a, b = [a, b].sort_by(&:last)
49
- b.last.send(op, a.last) && a.last.send(op, b.first)
36
+ a, b = [self, other].map(&:range)
37
+ #
38
+ # Although a Shift which passes through midnight is stored
39
+ # internally as lasting more than TimeOfDay::NUM_SECONDS_IN_DAY
40
+ # seconds from midnight, that's not how it is meant to be
41
+ # handled. Rather, it consists of two chunks:
42
+ #
43
+ # range.first => Midnight
44
+ # Midnight => range.last
45
+ #
46
+ # The second one is *before* the first. None of it is more than
47
+ # TimeOfDay::NUM_SECONDS_IN_DAY after midnight. We thus need to shift
48
+ # each of our ranges to cover all overlapping possibilities.
49
+ #
50
+ one_day = TimeOfDay::NUM_SECONDS_IN_DAY
51
+ ashifted =
52
+ Range.new(a.first + one_day, a.last + one_day, a.exclude_end?)
53
+ bshifted =
54
+ Range.new(b.first + one_day, b.last + one_day, b.exclude_end?)
55
+ #
56
+ # For exclusive ranges we need:
57
+ #
58
+ # a.ending > b.beginning && b.ending > a.beginning
59
+ #
60
+ # and for inclusive we need:
61
+ #
62
+ # a.ending >= b.beginning && b.ending >= a.beginning
63
+ #
64
+ aop = a.exclude_end? ? :> : :>=
65
+ bop = b.exclude_end? ? :> : :>=
66
+ #
67
+ (a.last.send(aop, b.first) && b.last.send(bop, a.first)) ||
68
+ (ashifted.last.send(aop, b.first) && b.last.send(bop, ashifted.first)) ||
69
+ (a.last.send(aop, bshifted.first) && bshifted.last.send(bop, a.first))
50
70
  end
51
71
 
52
72
  def contains?(shift)
@@ -34,8 +34,8 @@ module Tod
34
34
  /x
35
35
 
36
36
  WORDS = {
37
- "noon" => "12pm",
38
- "midnight" => "12am"
37
+ "noon" => "12pm".freeze,
38
+ "midnight" => "12am".freeze
39
39
  }
40
40
 
41
41
  NUM_SECONDS_IN_DAY = 86400
@@ -43,9 +43,9 @@ module Tod
43
43
  NUM_SECONDS_IN_MINUTE = 60
44
44
 
45
45
  FORMATS = {
46
- short: "%-l:%M %P",
47
- medium: "%-l:%M:%S %P",
48
- time: "%H:%M"
46
+ short: "%-l:%M %P".freeze,
47
+ medium: "%-l:%M:%S %P".freeze,
48
+ time: "%H:%M".freeze
49
49
  }
50
50
 
51
51
  def initialize(h, m=0, s=0)
@@ -89,7 +89,7 @@ module Tod
89
89
  def strftime(format_string)
90
90
  # Special case 2400 because strftime will load TimeOfDay into Time which
91
91
  # will convert 24 to 0
92
- format_string.gsub!(/%H|%k/, '24') if @hour == 24
92
+ format_string = format_string.gsub(/%H|%k/, '24') if @hour == 24
93
93
  Time.local(2000,1,1, @hour, @minute, @second).strftime(format_string)
94
94
  end
95
95
 
@@ -106,6 +106,10 @@ module Tod
106
106
  end
107
107
  alias_method :to_s, :to_formatted_s
108
108
 
109
+ def value_for_database
110
+ to_s
111
+ end
112
+
109
113
  # Return a new TimeOfDay num_seconds greater than self. It will wrap around
110
114
  # at midnight.
111
115
  def +(num_seconds)
@@ -200,25 +204,5 @@ module Tod
200
204
  def self.time_zone
201
205
  (Time.respond_to?(:zone) && Time.zone) || Time
202
206
  end
203
-
204
- def self.dump(time_of_day)
205
- time_of_day =
206
- if time_of_day.is_a? Hash
207
- # rails multiparam attribute
208
- # get hour, minute and second and construct new TimeOfDay object
209
- ::Tod::TimeOfDay.new(time_of_day[4], time_of_day[5], time_of_day[6])
210
- else
211
- # return nil, if input is not parsable
212
- Tod::TimeOfDay(time_of_day){}
213
- end
214
- time_of_day.to_s if time_of_day
215
- end
216
-
217
- def self.load(time)
218
- if time && !time.to_s.empty?
219
- return ::Tod::TimeOfDay.new(24) if time.respond_to?(:day) && time.day == 2 && time.hour == 0 && time.min == 0 && time.sec == 0
220
- ::Tod::TimeOfDay(time)
221
- end
222
- end
223
207
  end
224
208
  end
@@ -1,11 +1,18 @@
1
1
  module Tod
2
- class TimeOfDayType < ActiveRecord::Type::Value
2
+ class TimeOfDayType < ActiveModel::Type::Value
3
3
  def cast(value)
4
- TimeOfDay.load(value)
4
+ if value.is_a? Hash
5
+ # rails multiparam attribute
6
+ # get hour, minute and second and construct new TimeOfDay object
7
+ ::Tod::TimeOfDay.new(value[4], value[5], value[6])
8
+ else
9
+ # return nil, if input is not parsable
10
+ Tod::TimeOfDay(value){}
11
+ end
5
12
  end
6
13
 
7
14
  def serialize(value)
8
- TimeOfDay.dump(value)
15
+ value.to_s if value.present?
9
16
  end
10
17
  end
11
18
  end
data/lib/tod/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tod
2
- VERSION = "2.2.0"
2
+ VERSION = "3.0.0"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -4,7 +4,6 @@ require 'bundler/setup'
4
4
  require 'active_support/time'
5
5
  require 'tod'
6
6
  require 'tod/core_extensions'
7
- require 'tod/arel_extensions'
8
7
  require 'minitest/autorun'
9
8
  require 'pry'
10
9
 
@@ -99,6 +99,49 @@ describe "Shift" do
99
99
  shift2 = Tod::Shift.new(Tod::TimeOfDay.new(5), Tod::TimeOfDay.new(12), true)
100
100
  refute shift1.overlaps?(shift2)
101
101
  end
102
+
103
+ it "copes correctly with mixed shifts" do
104
+ shift1 = Tod::Shift.new(Tod::TimeOfDay.new(1), Tod::TimeOfDay.new(5))
105
+ shift2 = Tod::Shift.new(Tod::TimeOfDay.new(5), Tod::TimeOfDay.new(12), true)
106
+ assert shift1.overlaps?(shift2)
107
+ assert shift2.overlaps?(shift1)
108
+ shift1 = Tod::Shift.new(Tod::TimeOfDay.new(1), Tod::TimeOfDay.new(5), true)
109
+ shift2 = Tod::Shift.new(Tod::TimeOfDay.new(5), Tod::TimeOfDay.new(12))
110
+ refute shift1.overlaps?(shift2)
111
+ refute shift2.overlaps?(shift1)
112
+ end
113
+
114
+ it "copes correctly with zero length inclusive end shifts" do
115
+ shift1 = Tod::Shift.new(Tod::TimeOfDay.new(9), Tod::TimeOfDay.new(17))
116
+ shift2 = Tod::Shift.new(Tod::TimeOfDay.new(10), Tod::TimeOfDay.new(10))
117
+ shift3 = Tod::Shift.new(Tod::TimeOfDay.new(9), Tod::TimeOfDay.new(9))
118
+ shift4 = Tod::Shift.new(Tod::TimeOfDay.new(17), Tod::TimeOfDay.new(17))
119
+ assert shift1.overlaps?(shift2)
120
+ assert shift2.overlaps?(shift1)
121
+
122
+ assert shift1.overlaps?(shift3)
123
+ assert shift3.overlaps?(shift1)
124
+
125
+ assert shift1.overlaps?(shift4)
126
+ assert shift4.overlaps?(shift1)
127
+
128
+ end
129
+
130
+ it "copes correctly with zero length exclusive end shifts" do
131
+ shift1 = Tod::Shift.new(Tod::TimeOfDay.new(9), Tod::TimeOfDay.new(17), true)
132
+ shift2 = Tod::Shift.new(Tod::TimeOfDay.new(10), Tod::TimeOfDay.new(10), true)
133
+ shift3 = Tod::Shift.new(Tod::TimeOfDay.new(9), Tod::TimeOfDay.new(9), true)
134
+ shift4 = Tod::Shift.new(Tod::TimeOfDay.new(17), Tod::TimeOfDay.new(17), true)
135
+ assert shift1.overlaps?(shift2)
136
+ assert shift2.overlaps?(shift1)
137
+
138
+ refute shift1.overlaps?(shift3)
139
+ refute shift3.overlaps?(shift1)
140
+
141
+ refute shift1.overlaps?(shift4)
142
+ refute shift4.overlaps?(shift1)
143
+
144
+ end
102
145
  end
103
146
 
104
147
  describe "contains?" do
@@ -0,0 +1,74 @@
1
+ require_relative '../test_helper'
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','support/active_record'))
3
+
4
+ require 'tod/time_of_day_type'
5
+
6
+ ActiveModel::Type.register(:time_only, Tod::TimeOfDayType)
7
+ ActiveRecord::Type.register(:time_only, Tod::TimeOfDayType)
8
+
9
+ class Order < ActiveRecord::Base
10
+ attribute :time, :time_only
11
+ end
12
+
13
+ describe "TimeOfDay with ActiveRecord Attribute" do
14
+ it "sets time of day" do
15
+ Order.create!(time: Tod::TimeOfDay.new(9, 30))
16
+ end
17
+
18
+ it "sets nil as value" do
19
+ Order.create!(time: nil)
20
+ end
21
+
22
+ it "works with multiparam time arguments" do
23
+ order = Order.create!({"time(4i)" => "8", "time(5i)" => "6", "time(6i)" => "5"})
24
+ assert_equal Tod::TimeOfDay.new(8,6,5), order.time
25
+ end
26
+
27
+ it "should not raise Exception on access of unparsable values" do
28
+ order = Order.new(time: 'unparsable')
29
+ order.time
30
+ assert order.valid?
31
+ end
32
+
33
+ it "should dump unparsable values to nil" do
34
+ assert_nil Order.new(time: '').time
35
+ assert_nil Order.new(time: 'unparsable').time
36
+ assert_nil Order.new(time: nil).time
37
+ end
38
+
39
+ it "loads set Tod::TimeOfDay" do
40
+ time_of_day = Tod::TimeOfDay.new(9, 30)
41
+ order = Order.create!(time: time_of_day)
42
+ order.reload
43
+ assert_equal order.time, time_of_day
44
+ end
45
+
46
+ it "loads set Time" do
47
+ time_of_day = Time.new(2015, 10, 21, 16, 29, 0, "-07:00")
48
+ order = Order.create!(time: time_of_day)
49
+ order.reload
50
+ assert_equal order.time, Tod::TimeOfDay.new(16, 29)
51
+ end
52
+
53
+ it "returns nil if time is not set" do
54
+ order = Order.create!(time: nil)
55
+ order.reload
56
+ assert_nil order.time
57
+ end
58
+
59
+ it "dump 24:00:00 and get it back" do
60
+ time_of_day = Tod::TimeOfDay.new(24, 0, 0)
61
+ order = Order.create!(time: time_of_day)
62
+ order.reload
63
+ assert_equal Tod::TimeOfDay.new(24), order.time
64
+ end
65
+
66
+ describe "Order.where" do
67
+ it "handles TimeOfDay as a parameter" do
68
+ tod = Tod::TimeOfDay.new(11, 11)
69
+ expected = Order.create!(time: tod)
70
+ actual = Order.where(time: tod).first
71
+ assert_equal expected, actual
72
+ end
73
+ end
74
+ end
@@ -176,6 +176,13 @@ describe "TimeOfDay" do
176
176
  end
177
177
  end
178
178
 
179
+ describe "value_for_database" do
180
+ it "returns a formatted value for database query serialization" do
181
+ t = Tod::TimeOfDay.new(12,15,05)
182
+ assert_equal "12:15:05", t.value_for_database
183
+ end
184
+ end
185
+
179
186
  describe "to_s" do
180
187
  it "is aliased to to_formatted_s" do
181
188
  t = Tod::TimeOfDay.new(8,15,30)
data/tod.gemspec CHANGED
@@ -16,10 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.add_development_dependency "minitest"
17
17
  s.add_development_dependency "tzinfo"
18
18
  s.add_development_dependency "rake"
19
- s.add_development_dependency "activerecord", ">= 3.0.0"
19
+ s.add_development_dependency "activerecord", ">= 6.0.0"
20
20
  s.add_development_dependency "sqlite3"
21
21
  s.add_development_dependency "pry-byebug"
22
- s.add_development_dependency "arel"
23
22
 
24
23
  s.files = `git ls-files`.split("\n")
25
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tod
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Christensen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-10 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0
61
+ version: 6.0.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0
68
+ version: 6.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: arel
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
97
  description: Supplies TimeOfDay and Shift class that includes parsing, strftime, comparison,
112
98
  and arithmetic.
113
99
  email:
@@ -124,13 +110,7 @@ files:
124
110
  - MIT-LICENSE
125
111
  - README.markdown
126
112
  - Rakefile
127
- - gemfiles/4.0.gemfile
128
- - gemfiles/4.1.gemfile
129
- - gemfiles/4.2.gemfile
130
- - gemfiles/5.0.gemfile
131
- - gemfiles/5.2.gemfile
132
113
  - lib/tod.rb
133
- - lib/tod/arel_extensions.rb
134
114
  - lib/tod/conversions.rb
135
115
  - lib/tod/core_extensions.rb
136
116
  - lib/tod/date_extensions.rb
@@ -146,7 +126,7 @@ files:
146
126
  - test/tod/conversion_test.rb
147
127
  - test/tod/date_test.rb
148
128
  - test/tod/shift_test.rb
149
- - test/tod/time_of_day_serializable_attribute_test.rb
129
+ - test/tod/time_of_day_attribute_test.rb
150
130
  - test/tod/time_of_day_test.rb
151
131
  - test/tod/time_of_day_time_zone_with_active_support_test.rb
152
132
  - test/tod/time_test.rb
@@ -155,7 +135,7 @@ homepage: https://github.com/JackC/tod
155
135
  licenses:
156
136
  - MIT
157
137
  metadata: {}
158
- post_install_message:
138
+ post_install_message:
159
139
  rdoc_options: []
160
140
  require_paths:
161
141
  - lib
@@ -170,9 +150,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
150
  - !ruby/object:Gem::Version
171
151
  version: '0'
172
152
  requirements: []
173
- rubyforge_project:
174
- rubygems_version: 2.7.6
175
- signing_key:
153
+ rubygems_version: 3.0.6
154
+ signing_key:
176
155
  specification_version: 4
177
156
  summary: Supplies TimeOfDay and Shift class
178
- test_files: []
157
+ test_files:
158
+ - test/support/active_record.rb
159
+ - test/test_helper.rb
160
+ - test/tod/conversion_test.rb
161
+ - test/tod/date_test.rb
162
+ - test/tod/shift_test.rb
163
+ - test/tod/time_of_day_attribute_test.rb
164
+ - test/tod/time_of_day_test.rb
165
+ - test/tod/time_of_day_time_zone_with_active_support_test.rb
166
+ - test/tod/time_test.rb
data/gemfiles/4.0.gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "4.0.0"
4
-
5
- gemspec :path=>"../"
data/gemfiles/4.1.gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "~> 4.1.8"
4
-
5
- gemspec :path=>"../"
data/gemfiles/4.2.gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "~> 4.2.0"
4
-
5
- gemspec :path=>"../"
data/gemfiles/5.0.gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'activerecord', '~> 5.0.0.1'
4
-
5
- gemspec :path=>"../"
data/gemfiles/5.2.gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'activerecord', '~> 5.2.1'
4
-
5
- gemspec :path=>"../"
@@ -1,25 +0,0 @@
1
- require 'arel'
2
-
3
- module Tod
4
- module ArelDepthFirstExtensions
5
- def self.included(base)
6
- base.send :alias_method, :visit_Tod_TimeOfDay, :terminal
7
- end
8
- end
9
-
10
- module ArelDotExtensions
11
- def self.included(base)
12
- base.send :alias_method, :visit_Tod_TimeOfDay, :visit_String
13
- end
14
- end
15
-
16
- module ArelToSqlExtensions
17
- def visit_Tod_TimeOfDay(o, collector=nil)
18
- quote Tod::TimeOfDay.dump(o)
19
- end
20
- end
21
- end
22
-
23
- Arel::Visitors::DepthFirst.send :include, Tod::ArelDepthFirstExtensions
24
- Arel::Visitors::Dot.send :include, Tod::ArelDotExtensions
25
- Arel::Visitors::ToSql.send :include, Tod::ArelToSqlExtensions
@@ -1,73 +0,0 @@
1
- require_relative '../test_helper'
2
- require File.expand_path(File.join(File.dirname(__FILE__),'..','support/active_record'))
3
-
4
- class Order < ActiveRecord::Base
5
- serialize :time, Tod::TimeOfDay
6
- end
7
-
8
- describe "TimeOfDay with ActiveRecord Serializable Attribute" do
9
- describe ".dump" do
10
- it "sets time of day" do
11
- Order.create!(time: Tod::TimeOfDay.new(9, 30))
12
- end
13
-
14
- it "sets nil as value" do
15
- Order.create!(time: nil)
16
- end
17
-
18
- it "works with multiparam time arguments" do
19
- order = Order.create!({"time(4i)" => "8", "time(5i)" => "6", "time(6i)" => "5"})
20
- assert_equal Tod::TimeOfDay.new(8,6,5), order.time
21
- end
22
-
23
- it "should not raise Exception on access of unparsable values" do
24
- order = Order.new(time: 'unparsable')
25
- order.time
26
- assert order.valid?
27
- end
28
-
29
- it "should dump unparsable values to nil" do
30
- assert_nil Tod::TimeOfDay.dump('')
31
- assert_nil Tod::TimeOfDay.dump('unparsable')
32
- assert_nil Tod::TimeOfDay.dump(nil)
33
- end
34
- end
35
-
36
- describe ".load" do
37
- it "loads set Tod::TimeOfDay" do
38
- time_of_day = Tod::TimeOfDay.new(9, 30)
39
- order = Order.create!(time: time_of_day)
40
- order.reload
41
- assert_equal order.time, time_of_day
42
- end
43
-
44
- it "loads set Time" do
45
- time_of_day = Time.new(2015, 10, 21, 16, 29, 0, "-07:00")
46
- order = Order.create!(time: time_of_day)
47
- order.reload
48
- assert_equal order.time, Tod::TimeOfDay.new(16, 29)
49
- end
50
-
51
- it "returns nil if time is not set" do
52
- order = Order.create!(time: nil)
53
- order.reload
54
- assert_nil order.time
55
- end
56
-
57
- it "dump 24:00:00 and get it back" do
58
- time_of_day = Tod::TimeOfDay.new(24, 0, 0)
59
- order = Order.create!(time: time_of_day)
60
- order.reload
61
- assert_equal Tod::TimeOfDay.new(24), order.time
62
- end
63
- end
64
-
65
- describe "Order.where" do
66
- it "handles TimeOfDay as a parameter" do
67
- tod = Tod::TimeOfDay.new(11, 11)
68
- expected = Order.create!(time: tod)
69
- actual = Order.where(time: tod).first
70
- assert_equal expected, actual
71
- end
72
- end
73
- end