activerecord-time 0.10.1 → 0.17.0
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 +5 -5
- data/.rubocop.yml +23 -14
- data/.rubocop_todo.yml +81 -14
- data/.travis.yml +17 -31
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/activerecord-time.gemspec +10 -2
- data/gemfiles/ar51.gemfile +0 -1
- data/gemfiles/ar51.gemfile.lock +35 -43
- data/gemfiles/ar52.gemfile +0 -2
- data/gemfiles/ar52.gemfile.lock +36 -19
- data/gemfiles/{ar42.gemfile → ar60.gemfile} +1 -1
- data/gemfiles/{ar50.gemfile.lock → ar60.gemfile.lock} +31 -32
- data/gemfiles/{ar50.gemfile → ar61.gemfile} +1 -1
- data/gemfiles/common.gemfile +1 -1
- data/lib/activerecord-time.rb +3 -16
- data/lib/activerecord-time/{extension_5_0.rb → extension.rb} +5 -0
- data/lib/activerecord-time/version.rb +3 -1
- data/lib/time_of_day.rb +45 -2
- data/lib/time_of_day/core_ext.rb +9 -0
- data/matrix_test.rb +19 -5
- data/test/database.yml +0 -17
- data/test/schema.rb +2 -0
- data/test/test_helper.rb +6 -2
- data/test/time_of_day_test.rb +23 -22
- metadata +57 -19
- data/gemfiles/ar42.gemfile.lock +0 -77
- data/lib/activerecord-time/extension_4_2.rb +0 -31
- data/lib/activerecord-time/extension_until_4_1.rb +0 -71
data/gemfiles/ar52.gemfile.lock
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (5.2.
|
5
|
-
activesupport (= 5.2.
|
6
|
-
activerecord (5.2.
|
7
|
-
activemodel (= 5.2.
|
8
|
-
activesupport (= 5.2.
|
4
|
+
activemodel (5.2.3)
|
5
|
+
activesupport (= 5.2.3)
|
6
|
+
activerecord (5.2.3)
|
7
|
+
activemodel (= 5.2.3)
|
8
|
+
activesupport (= 5.2.3)
|
9
9
|
arel (>= 9.0)
|
10
|
-
|
10
|
+
activerecord-jdbc-adapter (52.3-java)
|
11
|
+
activerecord (~> 5.2.0)
|
12
|
+
activerecord-jdbcderby-adapter (0.8.2)
|
13
|
+
activerecord-jdbc-adapter (>= 0.8.2)
|
14
|
+
jdbc-derby (>= 10.3.2.1)
|
15
|
+
activerecord-jdbcpostgresql-adapter (52.3-java)
|
16
|
+
activerecord-jdbc-adapter (= 52.3)
|
17
|
+
jdbc-postgres (>= 9.4, < 43)
|
18
|
+
activerecord-jdbcsqlite3-adapter (52.3-java)
|
19
|
+
activerecord-jdbc-adapter (= 52.3)
|
20
|
+
jdbc-sqlite3 (~> 3.8, < 3.30)
|
21
|
+
activesupport (5.2.3)
|
11
22
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
23
|
i18n (>= 0.7, < 2)
|
13
24
|
minitest (~> 5.1)
|
@@ -15,28 +26,30 @@ GEM
|
|
15
26
|
ansi (1.5.0)
|
16
27
|
arel (9.0.0)
|
17
28
|
builder (3.2.3)
|
18
|
-
concurrent-ruby (1.
|
19
|
-
|
20
|
-
|
21
|
-
i18n (1.0.1)
|
29
|
+
concurrent-ruby (1.1.5)
|
30
|
+
docile (1.3.2)
|
31
|
+
i18n (1.7.0)
|
22
32
|
concurrent-ruby (~> 1.0)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
33
|
+
jdbc-derby (10.12.1.1)
|
34
|
+
jdbc-postgres (42.2.6)
|
35
|
+
jdbc-sqlite3 (3.28.0)
|
36
|
+
json (2.2.0)
|
37
|
+
json (2.2.0-java)
|
38
|
+
minitest (5.12.2)
|
39
|
+
minitest-reporters (1.4.1)
|
27
40
|
ansi
|
28
41
|
builder
|
29
42
|
minitest (>= 5.0)
|
30
43
|
ruby-progressbar
|
31
44
|
pg (0.21.0)
|
32
|
-
rake (
|
33
|
-
ruby-progressbar (1.
|
34
|
-
simplecov (0.
|
45
|
+
rake (13.0.0)
|
46
|
+
ruby-progressbar (1.10.1)
|
47
|
+
simplecov (0.17.1)
|
35
48
|
docile (~> 1.1)
|
36
49
|
json (>= 1.8, < 3)
|
37
50
|
simplecov-html (~> 0.10.0)
|
38
51
|
simplecov-html (0.10.2)
|
39
|
-
sqlite3 (1.
|
52
|
+
sqlite3 (1.4.1)
|
40
53
|
thread_safe (0.3.6)
|
41
54
|
thread_safe (0.3.6-java)
|
42
55
|
tzinfo (1.2.5)
|
@@ -48,6 +61,10 @@ PLATFORMS
|
|
48
61
|
|
49
62
|
DEPENDENCIES
|
50
63
|
activerecord (~> 5.2.0)
|
64
|
+
activerecord-jdbc-adapter
|
65
|
+
activerecord-jdbcderby-adapter
|
66
|
+
activerecord-jdbcpostgresql-adapter
|
67
|
+
activerecord-jdbcsqlite3-adapter
|
51
68
|
minitest-reporters
|
52
69
|
pg (< 1)
|
53
70
|
rake
|
@@ -55,4 +72,4 @@ DEPENDENCIES
|
|
55
72
|
sqlite3
|
56
73
|
|
57
74
|
BUNDLED WITH
|
58
|
-
1.
|
75
|
+
1.17.2
|
@@ -1,67 +1,66 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (
|
5
|
-
activesupport (=
|
6
|
-
activerecord (
|
7
|
-
activemodel (=
|
8
|
-
activesupport (=
|
9
|
-
|
10
|
-
|
11
|
-
activerecord (>= 2.2)
|
4
|
+
activemodel (6.0.2.1)
|
5
|
+
activesupport (= 6.0.2.1)
|
6
|
+
activerecord (6.0.2.1)
|
7
|
+
activemodel (= 6.0.2.1)
|
8
|
+
activesupport (= 6.0.2.1)
|
9
|
+
activerecord-jdbc-adapter (60.1-java)
|
10
|
+
activerecord (~> 6.0.0)
|
12
11
|
activerecord-jdbcderby-adapter (0.8.2)
|
13
12
|
activerecord-jdbc-adapter (>= 0.8.2)
|
14
13
|
jdbc-derby (>= 10.3.2.1)
|
15
|
-
activerecord-jdbcpostgresql-adapter (
|
16
|
-
activerecord-jdbc-adapter (
|
14
|
+
activerecord-jdbcpostgresql-adapter (60.1-java)
|
15
|
+
activerecord-jdbc-adapter (= 60.1)
|
17
16
|
jdbc-postgres (>= 9.4, < 43)
|
18
|
-
activerecord-jdbcsqlite3-adapter (
|
19
|
-
activerecord-jdbc-adapter (
|
17
|
+
activerecord-jdbcsqlite3-adapter (60.1-java)
|
18
|
+
activerecord-jdbc-adapter (= 60.1)
|
20
19
|
jdbc-sqlite3 (~> 3.8, < 3.30)
|
21
|
-
activesupport (
|
20
|
+
activesupport (6.0.2.1)
|
22
21
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
23
22
|
i18n (>= 0.7, < 2)
|
24
23
|
minitest (~> 5.1)
|
25
24
|
tzinfo (~> 1.1)
|
25
|
+
zeitwerk (~> 2.2)
|
26
26
|
ansi (1.5.0)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
docile (1.3.0)
|
32
|
-
i18n (1.0.1)
|
27
|
+
builder (3.2.4)
|
28
|
+
concurrent-ruby (1.1.5)
|
29
|
+
docile (1.3.2)
|
30
|
+
i18n (1.7.0)
|
33
31
|
concurrent-ruby (~> 1.0)
|
34
32
|
jdbc-derby (10.12.1.1)
|
35
|
-
jdbc-postgres (42.
|
36
|
-
jdbc-sqlite3 (3.
|
37
|
-
json (2.
|
38
|
-
json (2.
|
39
|
-
minitest (5.
|
40
|
-
minitest-reporters (1.2
|
33
|
+
jdbc-postgres (42.2.6)
|
34
|
+
jdbc-sqlite3 (3.28.0)
|
35
|
+
json (2.3.0)
|
36
|
+
json (2.3.0-java)
|
37
|
+
minitest (5.13.0)
|
38
|
+
minitest-reporters (1.4.2)
|
41
39
|
ansi
|
42
40
|
builder
|
43
41
|
minitest (>= 5.0)
|
44
42
|
ruby-progressbar
|
45
43
|
pg (0.21.0)
|
46
|
-
rake (
|
47
|
-
ruby-progressbar (1.
|
48
|
-
simplecov (0.
|
44
|
+
rake (13.0.1)
|
45
|
+
ruby-progressbar (1.10.1)
|
46
|
+
simplecov (0.17.1)
|
49
47
|
docile (~> 1.1)
|
50
48
|
json (>= 1.8, < 3)
|
51
49
|
simplecov-html (~> 0.10.0)
|
52
50
|
simplecov-html (0.10.2)
|
53
|
-
sqlite3 (1.
|
51
|
+
sqlite3 (1.4.2)
|
54
52
|
thread_safe (0.3.6)
|
55
53
|
thread_safe (0.3.6-java)
|
56
|
-
tzinfo (1.2.
|
54
|
+
tzinfo (1.2.6)
|
57
55
|
thread_safe (~> 0.1)
|
56
|
+
zeitwerk (2.2.2)
|
58
57
|
|
59
58
|
PLATFORMS
|
60
59
|
java
|
61
60
|
ruby
|
62
61
|
|
63
62
|
DEPENDENCIES
|
64
|
-
activerecord (~>
|
63
|
+
activerecord (~> 6.0.0)
|
65
64
|
activerecord-jdbc-adapter
|
66
65
|
activerecord-jdbcderby-adapter
|
67
66
|
activerecord-jdbcpostgresql-adapter
|
@@ -73,4 +72,4 @@ DEPENDENCIES
|
|
73
72
|
sqlite3
|
74
73
|
|
75
74
|
BUNDLED WITH
|
76
|
-
1.
|
75
|
+
1.17.2
|
data/gemfiles/common.gemfile
CHANGED
data/lib/activerecord-time.rb
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'activerecord-time/version'
|
2
|
-
require 'active_record/version'
|
3
4
|
require 'time_of_day'
|
4
5
|
require 'time_of_day/core_ext'
|
5
|
-
|
6
|
-
# TODO(uwe): Simplify when we stop supporting ActiveRecord 3.2
|
7
|
-
if ActiveRecord::VERSION::MAJOR < 3 ||
|
8
|
-
(ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR < 2)
|
9
|
-
raise 'activerecord-time only supports ActiveRecord 3.2.21 or later'
|
10
|
-
# TODO(uwe): Simplify when we stop supporting ActiveRecord 4.0 and 4.1
|
11
|
-
elsif ActiveRecord::VERSION::MAJOR == 3 ||
|
12
|
-
(ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR <= 1)
|
13
|
-
require 'activerecord-time/extension_until_4_1'
|
14
|
-
# TODO(uwe): Simplify when we stop supporting ActiveRecord 4.2
|
15
|
-
elsif ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2
|
16
|
-
require 'activerecord-time/extension_4_2'
|
17
|
-
elsif ActiveRecord.gem_version >= Gem::Version.new('5.0.0')
|
18
|
-
require 'activerecord-time/extension_5_0'
|
19
|
-
end
|
6
|
+
require 'activerecord-time/extension'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record/connection_adapters/abstract/quoting'
|
2
4
|
|
3
5
|
module Activerecord
|
@@ -5,11 +7,13 @@ module Activerecord
|
|
5
7
|
module Quoting
|
6
8
|
def _quote(value)
|
7
9
|
return "'#{value}'" if value.is_a?(TimeOfDay)
|
10
|
+
|
8
11
|
super(value)
|
9
12
|
end
|
10
13
|
|
11
14
|
def _type_cast(value)
|
12
15
|
return value.to_s if value.is_a?(TimeOfDay)
|
16
|
+
|
13
17
|
super(value)
|
14
18
|
end
|
15
19
|
end
|
@@ -26,6 +30,7 @@ module ActiveRecord
|
|
26
30
|
return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time)
|
27
31
|
return value unless value.is_a?(::String)
|
28
32
|
return if value.empty?
|
33
|
+
|
29
34
|
TimeOfDay._parse(value)
|
30
35
|
end
|
31
36
|
end
|
data/lib/time_of_day.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
|
3
5
|
class TimeOfDay
|
@@ -8,9 +10,16 @@ class TimeOfDay
|
|
8
10
|
attr_accessor :second # 0 - 59
|
9
11
|
|
10
12
|
def initialize(hour, minute = 0, second = 0)
|
11
|
-
|
13
|
+
if hour == 24
|
14
|
+
unless minute == 0 && second == 0
|
15
|
+
raise "Invalid TimeOfDay. #{hour}:#{minute}:#{second} given, but highest allowed value is 24:00:00"
|
16
|
+
end
|
17
|
+
else
|
18
|
+
raise "Invalid hour: #{hour}" unless hour >= 0 && hour <= 23
|
19
|
+
end
|
12
20
|
raise "Invalid minute: #{minute}" unless minute >= 0 && minute <= 59
|
13
21
|
raise "Invalid second: #{second}" unless second >= 0 && second <= 59
|
22
|
+
|
14
23
|
@hour = hour
|
15
24
|
@minute = minute
|
16
25
|
@second = second
|
@@ -32,29 +41,46 @@ class TimeOfDay
|
|
32
41
|
|
33
42
|
def self.parse(string)
|
34
43
|
return nil if string.blank?
|
44
|
+
|
35
45
|
tod = _parse(string)
|
36
46
|
raise ArgumentError, "Illegal time format: '#{string}'" unless tod
|
47
|
+
|
37
48
|
tod
|
38
49
|
end
|
39
50
|
|
40
51
|
def self._parse(string)
|
41
52
|
parts = parse_parts(string)
|
42
53
|
return unless parts
|
54
|
+
|
43
55
|
new(*parts)
|
44
56
|
end
|
45
57
|
|
46
58
|
def self.parse_parts(string)
|
47
59
|
return nil if string.blank?
|
48
60
|
return unless /^(?<hours>\d{1,2}):?(?<minutes>\d{2})?(?::(?<seconds>\d{1,2}))?$/ =~ string.strip
|
61
|
+
|
49
62
|
[hours.to_i, minutes.to_i, seconds.to_i]
|
50
63
|
end
|
51
64
|
|
65
|
+
def acts_like_time?
|
66
|
+
true
|
67
|
+
end
|
68
|
+
|
69
|
+
def in_time_zone(*)
|
70
|
+
self
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_time
|
74
|
+
on Date.today
|
75
|
+
end
|
76
|
+
|
52
77
|
def on(date)
|
53
78
|
Time.local(date.year, date.month, date.day, hour, minute, second) # rubocop: disable Rails/TimeZone
|
54
79
|
end
|
55
80
|
|
56
81
|
def +(other)
|
57
82
|
raise "Illegal argument: #{other.inspect}" unless other.is_a? Numeric
|
83
|
+
|
58
84
|
t = Time.local(0, 1, 1, hour, minute, second) # rubocop: disable Rails/TimeZone
|
59
85
|
t += other
|
60
86
|
self.class.new(t.hour, t.min, t.sec)
|
@@ -62,11 +88,13 @@ class TimeOfDay
|
|
62
88
|
|
63
89
|
def -(other)
|
64
90
|
raise "Illegal argument: #{other.inspect}" unless other.is_a? Numeric
|
91
|
+
|
65
92
|
self.+(-other)
|
66
93
|
end
|
67
94
|
|
68
95
|
def <=>(other)
|
69
96
|
return -1 unless other
|
97
|
+
|
70
98
|
other_tod = if other.is_a?(TimeOfDay)
|
71
99
|
other
|
72
100
|
elsif other.respond_to?(:time_of_day)
|
@@ -78,8 +106,19 @@ class TimeOfDay
|
|
78
106
|
to_a <=> [other_tod.hour, other_tod.minute, other_tod.second]
|
79
107
|
end
|
80
108
|
|
109
|
+
# Referring to the same H/M/S makes objects equal.
|
110
|
+
# and we only want one hash key.
|
111
|
+
def hash
|
112
|
+
@hour.hash ^ @minute.hash ^ @second.hash
|
113
|
+
end
|
114
|
+
|
115
|
+
# Referring to the same H/M/S makes objects equal.
|
116
|
+
def eql?(other)
|
117
|
+
hash == other.hash
|
118
|
+
end
|
119
|
+
|
81
120
|
def strftime(format)
|
82
|
-
on(Date.today).strftime(format)
|
121
|
+
on(Date.today).strftime(format)
|
83
122
|
end
|
84
123
|
|
85
124
|
def to_s(with_seconds = true)
|
@@ -92,6 +131,10 @@ class TimeOfDay
|
|
92
131
|
"#{@hour.inspect}:#{@minute.inspect}:#{@second.inspect}"
|
93
132
|
end
|
94
133
|
|
134
|
+
def inspect
|
135
|
+
"#<#{self.class} hour=#{@hour}, minute=#{@minute}, second=#{@second}>"
|
136
|
+
end
|
137
|
+
|
95
138
|
def to_a
|
96
139
|
[@hour, @minute, @second]
|
97
140
|
end
|
data/lib/time_of_day/core_ext.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time_of_day'
|
2
4
|
|
3
5
|
class Time
|
@@ -6,6 +8,12 @@ class Time
|
|
6
8
|
end
|
7
9
|
end
|
8
10
|
|
11
|
+
class ActiveSupport::TimeWithZone
|
12
|
+
def time_of_day
|
13
|
+
TimeOfDay.new(hour, min, sec)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
9
17
|
class Date
|
10
18
|
def at(time_of_day)
|
11
19
|
time_of_day = TimeOfDay.parse(time_of_day) if time_of_day.is_a?(String)
|
@@ -21,6 +29,7 @@ module Kernel
|
|
21
29
|
unless ints.empty?
|
22
30
|
raise(ArgumentError, 'TimeOfDay() takes a string or multiple integers as arguments')
|
23
31
|
end
|
32
|
+
|
24
33
|
TimeOfDay.parse(string_or_int)
|
25
34
|
else
|
26
35
|
TimeOfDay.new(string_or_int, *ints)
|
data/matrix_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby -w
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
system('rubocop --auto-correct') || exit(1)
|
4
5
|
|
@@ -16,6 +17,7 @@ def run_script(ruby, env, gemfile)
|
|
16
17
|
puts
|
17
18
|
system("chruby-exec #{ruby} -- bundle exec rake") || exit(1)
|
18
19
|
puts '*' * 80
|
20
|
+
puts
|
19
21
|
end
|
20
22
|
|
21
23
|
def use_gemfile(ruby, gemfile, update_gemfiles)
|
@@ -23,6 +25,7 @@ def use_gemfile(ruby, gemfile, update_gemfiles)
|
|
23
25
|
puts "Testing #{gemfile}"
|
24
26
|
puts
|
25
27
|
ENV['BUNDLE_GEMFILE'] = gemfile
|
28
|
+
system "chruby-exec #{ruby} -- bundle -v"
|
26
29
|
if update_gemfiles
|
27
30
|
system "chruby-exec #{ruby} -- bundle update"
|
28
31
|
else
|
@@ -33,19 +36,30 @@ def use_gemfile(ruby, gemfile, update_gemfiles)
|
|
33
36
|
puts '$' * 80
|
34
37
|
end
|
35
38
|
|
36
|
-
bad_variants = (travis
|
39
|
+
bad_variants = (travis.dig('matrix', 'exclude').to_a + travis.dig('matrix', 'allow_failures').to_a)
|
40
|
+
|
41
|
+
travis['env']['global'].each do |env|
|
42
|
+
env.scan(/\b(?<key>[A-Z_]+)="(?<value>.+?)"/) do |key, value|
|
43
|
+
ENV[key] = value
|
44
|
+
end
|
45
|
+
end
|
37
46
|
|
38
47
|
travis['rvm'].each do |ruby|
|
39
|
-
next if
|
48
|
+
next if /head/.match?(ruby) # ruby-install does not support HEAD installation
|
49
|
+
|
40
50
|
puts '#' * 80
|
41
51
|
puts "Testing #{ruby}"
|
42
52
|
puts
|
43
53
|
system "ruby-install --no-reinstall #{ruby}" || exit(1)
|
44
|
-
|
45
|
-
|
54
|
+
bundler_version = '1.17.2'
|
55
|
+
gem_cmd = "chruby-exec #{ruby} -- gem"
|
56
|
+
system "#{gem_cmd} uninstall --force --all --version '!=#{bundler_version}' bundler"
|
57
|
+
bundler_gem_check_cmd = "#{gem_cmd} query -i -n '^bundler$' -v '#{bundler_version}' >/dev/null"
|
58
|
+
bundler_install_cmd = "#{gem_cmd} install bundler -v '#{bundler_version}'"
|
59
|
+
system "#{bundler_gem_check_cmd} || #{bundler_install_cmd}" || exit(1)
|
46
60
|
travis['gemfile'].each do |gemfile|
|
47
61
|
use_gemfile(ruby, gemfile, update_gemfiles) do
|
48
|
-
travis['env'].each do |env|
|
62
|
+
travis['env']['matrix'].each do |env|
|
49
63
|
bad_variant = bad_variants.any? do |f|
|
50
64
|
(f['rvm'].nil? || f['rvm'] == ruby) &&
|
51
65
|
(f['gemfile'].nil? || f['gemfile'] == gemfile) && (f['env'].nil? || f['env'] == env)
|