activerecord-time 0.12.0 → 0.14.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
- SHA1:
3
- metadata.gz: 877aec8ae6f1cf15a3730b23a0f1c2e6ea1f403c
4
- data.tar.gz: 1fc6b3270f3a8f2259695e3b3ae13d4f86122421
2
+ SHA256:
3
+ metadata.gz: 3dd9c896468de348081c956b30ff978ecc973a5e59c15e023d0ea1d6744fc790
4
+ data.tar.gz: 159d2a9796c4598d06d56f1516e61f66ca0867f46d2211ef48b825aa6cb8798c
5
5
  SHA512:
6
- metadata.gz: b0dcf17261de5d998597d32895bc2eeb11f2f749d9d5d829370f2653b2fe8e14daac265b3242f094efaee29aa8daa111b08f774c82865cc80a95845b02dacca3
7
- data.tar.gz: 15cbb911123ef1a9ddd07ebe6799ea24823e196681203d37c22c598192378fa67edbfb8828efa64993bfb60b7b5784db0c69997de385a6d50abec8bbcb7a1984
6
+ metadata.gz: 6b978dd14a0c88e93876abde8e54e61831e46039f7c976110fa0ed228094ec9ca515d06f34fb112cb770dcc641f08ec47e45504090a3e2bd0ef390f98b1a114b
7
+ data.tar.gz: f70e7fb91f7c85692a3d9b9529bbf8f10cd531a46dce434757783d56ad9a7f86b740430ac1ee0d97577052da45c441744d50da7ccb4efcd305b0ad05e8fd40c1
data/.rubocop.yml CHANGED
@@ -1,25 +1,29 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+ require:
3
+ - rubocop-performance
4
+ - rubocop-rails
2
5
 
3
6
  AllCops:
4
- TargetRubyVersion: 2.2
7
+ TargetRubyVersion: 2.4
5
8
  DisplayCopNames: true
6
9
  DisplayStyleGuide: true
7
10
  Include:
8
11
  - '**/Gemfile'
9
12
  - '**/Rakefile'
13
+ - '**/*.rb'
10
14
 
11
15
  Layout/AlignParameters:
12
16
  EnforcedStyle: with_fixed_indentation
13
17
  IndentationWidth: 4
14
18
 
15
- Layout/FirstParameterIndentation:
19
+ Layout/IndentFirstArgument:
16
20
  EnforcedStyle: consistent
17
21
  IndentationWidth: 4
18
22
 
19
- Layout/IndentArray:
23
+ Layout/IndentFirstArrayElement:
20
24
  EnforcedStyle: consistent
21
25
 
22
- Layout/IndentHash:
26
+ Layout/IndentFirstHashElement:
23
27
  EnforcedStyle: consistent
24
28
 
25
29
  Layout/IndentAssignment:
data/.rubocop_todo.yml CHANGED
@@ -1,18 +1,20 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2018-05-03 15:54:21 +0200 using RuboCop version 0.55.0.
3
+ # on 2019-11-07 12:06:57 +0100 using RuboCop version 0.76.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 4
9
+ # Offense count: 3
10
10
  Metrics/AbcSize:
11
- Max: 34
11
+ Max: 33
12
12
 
13
- # Offense count: 4
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ # ExcludedMethods: refine
14
16
  Metrics/BlockLength:
15
- Max: 26
17
+ Max: 28
16
18
 
17
19
  # Offense count: 1
18
20
  # Configuration parameters: CountComments.
@@ -24,20 +26,54 @@ Metrics/CyclomaticComplexity:
24
26
  Max: 7
25
27
 
26
28
  # Offense count: 2
27
- # Configuration parameters: CountComments.
29
+ # Configuration parameters: CountComments, ExcludedMethods.
28
30
  Metrics/MethodLength:
29
31
  Max: 16
30
32
 
33
+ # Offense count: 1
34
+ # Configuration parameters: EnforcedStyle.
35
+ # SupportedStyles: strict, flexible
36
+ Rails/Date:
37
+ Exclude:
38
+ - 'lib/time_of_day.rb'
39
+
31
40
  # Offense count: 2
32
41
  # Cop supports --auto-correct.
33
- Rails/ActiveRecordAliases:
42
+ Security/YAMLLoad:
34
43
  Exclude:
44
+ - 'test/test_helper.rb'
35
45
  - 'test/time_of_day_test.rb'
36
46
 
37
- # Offense count: 3
47
+ # Offense count: 1
48
+ # Configuration parameters: .
49
+ # SupportedStyles: inline, group
50
+ Style/AccessModifierDeclarations:
51
+ EnforcedStyle: inline
52
+
53
+ # Offense count: 1
38
54
  # Cop supports --auto-correct.
39
- Security/YAMLLoad:
55
+ # Configuration parameters: AutoCorrect, EnforcedStyle.
56
+ # SupportedStyles: nested, compact
57
+ Style/ClassAndModuleChildren:
58
+ Exclude:
59
+ - 'lib/time_of_day/core_ext.rb'
60
+
61
+ # Offense count: 5
62
+ # Configuration parameters: .
63
+ # SupportedStyles: annotated, template, unannotated
64
+ Style/FormatStringToken:
65
+ EnforcedStyle: unannotated
66
+
67
+ # Offense count: 2
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: EnforcedStyle.
70
+ # SupportedStyles: always, never
71
+ Style/FrozenStringLiteralComment:
72
+ Exclude:
73
+ - 'Gemfile'
74
+ - 'Rakefile'
75
+
76
+ # Offense count: 4
77
+ Style/IdenticalConditionalBranches:
40
78
  Exclude:
41
- - 'matrix_test.rb'
42
- - 'test/test_helper.rb'
43
79
  - 'test/time_of_day_test.rb'
data/.travis.yml CHANGED
@@ -1,39 +1,27 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ cache: bundler
4
+ services:
5
+ - postgresql
3
6
  jdk:
4
- - oraclejdk8
5
- before_install: gem install bundler # TODO(uwe): https://github.com/travis-ci/travis-ci/issues/9383
7
+ - openjdk8
6
8
  rvm:
7
- - ruby-2.5.1
8
- - ruby-2.4.4
9
- - jruby-9.1.17.0
10
- - ruby-2.3.7
11
- - ruby-2.2.10
9
+ - ruby-2.6
10
+ - ruby-2.5
11
+ - ruby-2.4
12
+ - jruby
12
13
  gemfile:
13
14
  - gemfiles/ar52.gemfile
14
15
  - gemfiles/ar51.gemfile
15
- - gemfiles/ar50.gemfile
16
- - gemfiles/ar42.gemfile
17
16
  env:
18
- - JRUBY_OPTS="--dev --debug" ADAPTER="postgresql"
19
- - JRUBY_OPTS="--dev --debug" ADAPTER="derby"
20
- - JRUBY_OPTS="--dev --debug" ADAPTER="sqlite3"
17
+ global:
18
+ - JRUBY_OPTS="--dev --debug"
19
+ matrix:
20
+ - ADAPTER="postgresql"
21
+ - ADAPTER="sqlite3"
21
22
  matrix:
22
23
  allow_failures:
23
- - rvm: jruby-9.1.17.0
24
- gemfile: gemfiles/ar52.gemfile
25
- - rvm: jruby-9.1.17.0
26
- gemfile: gemfiles/ar51.gemfile
27
- - rvm: jruby-9.1.17.0
28
- gemfile: gemfiles/ar50.gemfile
29
- - rvm: jruby-9.1.17.0
30
- gemfile: gemfiles/ar42.gemfile
31
- exclude:
32
- - rvm: ruby-2.5.1
33
- env: JRUBY_OPTS="--dev --debug" ADAPTER="derby"
34
- - rvm: ruby-2.4.4
35
- env: JRUBY_OPTS="--dev --debug" ADAPTER="derby"
36
- - rvm: ruby-2.3.7
37
- env: JRUBY_OPTS="--dev --debug" ADAPTER="derby"
38
- - rvm: ruby-2.2.10
39
- env: JRUBY_OPTS="--dev --debug" ADAPTER="derby"
24
+ - rvm: jruby
25
+ env: ADAPTER="sqlite3"
26
+ - rvm: jruby
27
+ env: ADAPTER="sqlite3"
@@ -1,3 +1,8 @@
1
+ begin
2
+ require 'english'
3
+ rescue LoadError
4
+ end
5
+
1
6
  lib = File.expand_path('lib', __dir__)
2
7
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
8
  require 'activerecord-time/version'
@@ -11,14 +16,14 @@ Gem::Specification.new do |gem|
11
16
  gem.summary = 'A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.'
12
17
  gem.homepage = 'https://github.com/donv/activerecord-time'
13
18
  gem.license = 'MIT'
14
- gem.required_ruby_version = '>= 2.2'
19
+ gem.required_ruby_version = '>= 2.4'
15
20
 
16
21
  gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
22
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
23
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
24
  gem.require_paths = %w[lib]
20
25
 
21
- gem.add_runtime_dependency 'activerecord', '>=4.2', '<6'
26
+ gem.add_runtime_dependency 'activerecord', '>=5.1', '<6'
22
27
 
23
28
  if defined? JRUBY_VERSION
24
29
  gem.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
@@ -30,5 +35,7 @@ Gem::Specification.new do |gem|
30
35
  gem.add_development_dependency 'minitest-reporters'
31
36
  gem.add_development_dependency 'rake'
32
37
  gem.add_development_dependency 'rubocop'
38
+ gem.add_development_dependency 'rubocop-performance'
39
+ gem.add_development_dependency 'rubocop-rails'
33
40
  gem.add_development_dependency 'simplecov'
34
41
  end
@@ -1,4 +1,3 @@
1
- RAILS_5 = true
2
1
  eval File.read("#{File.dirname __FILE__}/common.gemfile")
3
2
 
4
3
  gem 'activerecord', '~>5.1.1'
@@ -1,31 +1,24 @@
1
- GIT
2
- remote: https://github.com/jruby/activerecord-jdbc-adapter.git
3
- revision: cfea62ad56141c9e3c5348797028d45b64a193ca
4
- specs:
5
- activerecord-jdbc-adapter (51.0-java)
6
- activerecord (~> 5.1.0)
7
- activerecord-jdbcderby-adapter (51.0)
8
- activerecord-jdbc-adapter (~> 51.0)
9
- jdbc-derby (~> 10.6)
10
- activerecord-jdbcpostgresql-adapter (51.0)
11
- activerecord-jdbc-adapter (~> 51.0)
12
- jdbc-postgres (>= 9.4, < 43)
13
- activerecord-jdbcsqlite3-adapter (51.0)
14
- activerecord-jdbc-adapter (~> 51.0)
15
- jdbc-sqlite3 (~> 3.8, < 3.30)
16
- jdbc-postgres (42.1.4)
17
- jdbc-sqlite3 (3.20.1)
18
-
19
1
  GEM
20
2
  remote: https://rubygems.org/
21
3
  specs:
22
- activemodel (5.1.6)
23
- activesupport (= 5.1.6)
24
- activerecord (5.1.6)
25
- activemodel (= 5.1.6)
26
- activesupport (= 5.1.6)
4
+ activemodel (5.1.7)
5
+ activesupport (= 5.1.7)
6
+ activerecord (5.1.7)
7
+ activemodel (= 5.1.7)
8
+ activesupport (= 5.1.7)
27
9
  arel (~> 8.0)
28
- activesupport (5.1.6)
10
+ activerecord-jdbc-adapter (51.4-java)
11
+ activerecord (~> 5.1.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 (51.4-java)
16
+ activerecord-jdbc-adapter (= 51.4)
17
+ jdbc-postgres (>= 9.4, < 43)
18
+ activerecord-jdbcsqlite3-adapter (51.4-java)
19
+ activerecord-jdbc-adapter (= 51.4)
20
+ jdbc-sqlite3 (~> 3.8, < 3.30)
21
+ activesupport (5.1.7)
29
22
  concurrent-ruby (~> 1.0, >= 1.0.2)
30
23
  i18n (>= 0.7, < 2)
31
24
  minitest (~> 5.1)
@@ -33,29 +26,30 @@ GEM
33
26
  ansi (1.5.0)
34
27
  arel (8.0.0)
35
28
  builder (3.2.3)
36
- concurrent-ruby (1.0.5)
37
- concurrent-ruby (1.0.5-java)
38
- docile (1.3.0)
39
- i18n (1.0.1)
29
+ concurrent-ruby (1.1.5)
30
+ docile (1.3.2)
31
+ i18n (1.7.0)
40
32
  concurrent-ruby (~> 1.0)
41
33
  jdbc-derby (10.12.1.1)
42
- json (2.1.0)
43
- json (2.1.0-java)
44
- minitest (5.10.3)
45
- minitest-reporters (1.2.0)
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)
46
40
  ansi
47
41
  builder
48
42
  minitest (>= 5.0)
49
43
  ruby-progressbar
50
44
  pg (0.21.0)
51
- rake (12.3.1)
52
- ruby-progressbar (1.9.0)
53
- simplecov (0.16.1)
45
+ rake (13.0.0)
46
+ ruby-progressbar (1.10.1)
47
+ simplecov (0.17.1)
54
48
  docile (~> 1.1)
55
49
  json (>= 1.8, < 3)
56
50
  simplecov-html (~> 0.10.0)
57
51
  simplecov-html (0.10.2)
58
- sqlite3 (1.3.13)
52
+ sqlite3 (1.4.1)
59
53
  thread_safe (0.3.6)
60
54
  thread_safe (0.3.6-java)
61
55
  tzinfo (1.2.5)
@@ -67,12 +61,10 @@ PLATFORMS
67
61
 
68
62
  DEPENDENCIES
69
63
  activerecord (~> 5.1.1)
70
- activerecord-jdbc-adapter!
71
- activerecord-jdbcderby-adapter!
72
- activerecord-jdbcpostgresql-adapter!
73
- activerecord-jdbcsqlite3-adapter!
74
- jdbc-postgres!
75
- jdbc-sqlite3!
64
+ activerecord-jdbc-adapter
65
+ activerecord-jdbcderby-adapter
66
+ activerecord-jdbcpostgresql-adapter
67
+ activerecord-jdbcsqlite3-adapter
76
68
  minitest-reporters
77
69
  pg (< 1)
78
70
  rake
@@ -80,4 +72,4 @@ DEPENDENCIES
80
72
  sqlite3
81
73
 
82
74
  BUNDLED WITH
83
- 1.16.1
75
+ 1.17.2
@@ -1,5 +1,3 @@
1
- SKIP_JRUBY = true
2
-
3
1
  eval File.read("#{File.dirname __FILE__}/common.gemfile")
4
2
 
5
3
  gem 'activerecord', '~>5.2.0'
@@ -1,13 +1,24 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activemodel (5.2.0)
5
- activesupport (= 5.2.0)
6
- activerecord (5.2.0)
7
- activemodel (= 5.2.0)
8
- activesupport (= 5.2.0)
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
- activesupport (5.2.0)
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.0.5)
19
- concurrent-ruby (1.0.5-java)
20
- docile (1.3.0)
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
- json (2.1.0)
24
- json (2.1.0-java)
25
- minitest (5.10.3)
26
- minitest-reporters (1.2.0)
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 (12.3.1)
33
- ruby-progressbar (1.9.0)
34
- simplecov (0.16.1)
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.3.13)
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.16.1
75
+ 1.17.2
@@ -1,11 +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 4.2
7
- if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 2
8
- require 'activerecord-time/extension_4_2'
9
- elsif ActiveRecord.gem_version >= Gem::Version.new('5.0.0')
10
- require 'activerecord-time/extension_5_0'
11
- 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
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Activerecord
2
4
  module Time
3
- VERSION = '0.12.0'.freeze
5
+ VERSION = '0.14.0'
4
6
  end
5
7
  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,14 @@ class TimeOfDay
8
10
  attr_accessor :second # 0 - 59
9
11
 
10
12
  def initialize(hour, minute = 0, second = 0)
11
- raise "Invalid hour: #{hour}" unless hour >= 0 && hour <= 23
13
+ if hour == 24
14
+ raise "Invalid TimeOfDay. #{hour}:#{minute}:#{second} given, but highest allowed value is 24:00:00" unless minute == 0 && second == 0
15
+ else
16
+ raise "Invalid hour: #{hour}" unless hour >= 0 && hour <= 23
17
+ end
12
18
  raise "Invalid minute: #{minute}" unless minute >= 0 && minute <= 59
13
19
  raise "Invalid second: #{second}" unless second >= 0 && second <= 59
20
+
14
21
  @hour = hour
15
22
  @minute = minute
16
23
  @second = second
@@ -32,20 +39,24 @@ class TimeOfDay
32
39
 
33
40
  def self.parse(string)
34
41
  return nil if string.blank?
42
+
35
43
  tod = _parse(string)
36
44
  raise ArgumentError, "Illegal time format: '#{string}'" unless tod
45
+
37
46
  tod
38
47
  end
39
48
 
40
49
  def self._parse(string)
41
50
  parts = parse_parts(string)
42
51
  return unless parts
52
+
43
53
  new(*parts)
44
54
  end
45
55
 
46
56
  def self.parse_parts(string)
47
57
  return nil if string.blank?
48
58
  return unless /^(?<hours>\d{1,2}):?(?<minutes>\d{2})?(?::(?<seconds>\d{1,2}))?$/ =~ string.strip
59
+
49
60
  [hours.to_i, minutes.to_i, seconds.to_i]
50
61
  end
51
62
 
@@ -57,12 +68,17 @@ class TimeOfDay
57
68
  self
58
69
  end
59
70
 
71
+ def to_time
72
+ on Date.today
73
+ end
74
+
60
75
  def on(date)
61
76
  Time.local(date.year, date.month, date.day, hour, minute, second) # rubocop: disable Rails/TimeZone
62
77
  end
63
78
 
64
79
  def +(other)
65
80
  raise "Illegal argument: #{other.inspect}" unless other.is_a? Numeric
81
+
66
82
  t = Time.local(0, 1, 1, hour, minute, second) # rubocop: disable Rails/TimeZone
67
83
  t += other
68
84
  self.class.new(t.hour, t.min, t.sec)
@@ -70,11 +86,13 @@ class TimeOfDay
70
86
 
71
87
  def -(other)
72
88
  raise "Illegal argument: #{other.inspect}" unless other.is_a? Numeric
89
+
73
90
  self.+(-other)
74
91
  end
75
92
 
76
93
  def <=>(other)
77
94
  return -1 unless other
95
+
78
96
  other_tod = if other.is_a?(TimeOfDay)
79
97
  other
80
98
  elsif other.respond_to?(:time_of_day)
@@ -87,7 +105,7 @@ class TimeOfDay
87
105
  end
88
106
 
89
107
  def strftime(format)
90
- on(Date.today).strftime(format) # rubocop: disable Rails/Date
108
+ on(Date.today).strftime(format)
91
109
  end
92
110
 
93
111
  def to_s(with_seconds = true)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time_of_day'
2
4
 
3
5
  class Time
@@ -27,6 +29,7 @@ module Kernel
27
29
  unless ints.empty?
28
30
  raise(ArgumentError, 'TimeOfDay() takes a string or multiple integers as arguments')
29
31
  end
32
+
30
33
  TimeOfDay.parse(string_or_int)
31
34
  else
32
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,16 +36,21 @@ def use_gemfile(ruby, gemfile, update_gemfiles)
33
36
  puts '$' * 80
34
37
  end
35
38
 
36
- bad_variants = (travis['matrix']['exclude'].to_a + travis['matrix']['allow_failures'].to_a)
39
+ bad_variants = (travis.dig('matrix', 'exclude').to_a + travis.dig('matrix', 'allow_failures').to_a)
37
40
 
38
41
  travis['rvm'].each do |ruby|
39
- next if ruby =~ /head/ # ruby-install does not support HEAD installation
42
+ next if /head/.match?(ruby) # ruby-install does not support HEAD installation
43
+
40
44
  puts '#' * 80
41
45
  puts "Testing #{ruby}"
42
46
  puts
43
47
  system "ruby-install --no-reinstall #{ruby}" || exit(1)
44
- bundler_gem_check_cmd = "chruby-exec #{ruby} -- gem query -i -n bundler >/dev/null"
45
- system "#{bundler_gem_check_cmd} || chruby-exec #{ruby} -- gem install bundler" || exit(1)
48
+ bundler_version = '1.17.2'
49
+ gem_cmd = "chruby-exec #{ruby} -- gem"
50
+ system "#{gem_cmd} uninstall --force --all --version '!=#{bundler_version}' bundler"
51
+ bundler_gem_check_cmd = "#{gem_cmd} query -i -n '^bundler$' -v '#{bundler_version}' >/dev/null"
52
+ bundler_install_cmd = "#{gem_cmd} install bundler -v '#{bundler_version}'"
53
+ system "#{bundler_gem_check_cmd} || #{bundler_install_cmd}" || exit(1)
46
54
  travis['gemfile'].each do |gemfile|
47
55
  use_gemfile(ruby, gemfile, update_gemfiles) do
48
56
  travis['env'].each do |env|
data/test/database.yml CHANGED
@@ -1,6 +1,3 @@
1
- sqlite:
2
- :adapter: sqlite
3
- :dbfile: plugin.sqlite.db
4
1
  sqlite3:
5
2
  :adapter: sqlite3
6
3
  :dbfile: ":memory:"
@@ -12,17 +9,3 @@ postgresql:
12
9
  :password:
13
10
  :database: activerecord-time_test
14
11
  :min_messages: ERROR
15
- mysql:
16
- :adapter: mysql
17
- :host: localhost
18
- :username: rails
19
- :password:
20
- :database: activerecord-time_test
21
- derby:
22
- :adapter: derby
23
- :driver: org.apache.derby.jdbc.EmbeddedDriver
24
- :url: jdbc:derby:activerecord-time_test-derby;user=derby;create=true",
25
- :username: derby
26
- :pool: 50
27
- :transaction_isolation: false
28
- :database: activerecord-time_test-derby
data/test/schema.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ActiveRecord::Schema.define(version: 1) do
2
4
  create_table :events do |t|
3
5
  t.string :name
data/test/test_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
4
  RAILS_ROOT = File.dirname(__FILE__)
3
5
 
@@ -13,8 +15,10 @@ require 'logger'
13
15
  require 'fileutils'
14
16
  require 'yaml'
15
17
 
16
- require 'simplecov'
17
- SimpleCov.start
18
+ if defined?(Rake) && (RUBY_ENGINE != 'jruby' || org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED)
19
+ require 'simplecov'
20
+ SimpleCov.start
21
+ end
18
22
 
19
23
  FileUtils.rm_rf File.expand_path(':memory:', File.dirname(__FILE__))
20
24
  config = YAML.load(IO.read(File.dirname(__FILE__) + '/database.yml'))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path('test_helper', File.dirname(__FILE__))
2
4
 
3
5
  class ApplicationRecord < ActiveRecord::Base
@@ -6,10 +8,6 @@ end
6
8
  class Event < ApplicationRecord
7
9
  end
8
10
 
9
- # TODO(uwe): Remove when we stop testing ActiveRecord 4.0
10
- Minitest::Test = Minitest::Unit unless defined? Minitest::Test
11
- # ODOT
12
-
13
11
  class TimeOfDayTest < Minitest::Test
14
12
  def setup
15
13
  @twelve_o_clock = TimeOfDay.parse '12:00:00'
@@ -58,12 +56,12 @@ class TimeOfDayTest < Minitest::Test
58
56
  end
59
57
 
60
58
  def test_parse_immutable_string
61
- tod = TimeOfDay.parse('10:01'.freeze)
59
+ tod = TimeOfDay.parse('10:01')
62
60
  assert_equal 10, tod.hour
63
61
  assert_equal 1, tod.minute
64
62
  assert_equal 0, tod.second
65
63
 
66
- tod = TimeOfDay.parse('23:59:59'.freeze)
64
+ tod = TimeOfDay.parse('23:59:59')
67
65
  assert_equal 23, tod.hour
68
66
  assert_equal 59, tod.minute
69
67
  assert_equal 59, tod.second
@@ -107,14 +105,7 @@ class TimeOfDayTest < Minitest::Test
107
105
  assert_nil Event.where('start_at < ?', @twelve_o_clock).first
108
106
  assert_nil Event.where('start_at > ?', @twelve_o_clock).first
109
107
 
110
- # TODO(uwe): Simplify when we stop supporting ActiveRecord 3
111
- if ActiveRecord::VERSION::MAJOR >= 4
112
- t.update! start_at: TimeOfDay.new(13)
113
- else
114
- t.update_attributes! start_at: TimeOfDay.new(13)
115
- end
116
- # ODOT
117
-
108
+ t.update! start_at: TimeOfDay.new(13)
118
109
  t.destroy
119
110
  end
120
111
 
@@ -124,13 +115,7 @@ class TimeOfDayTest < Minitest::Test
124
115
  e = Event.where(content: text).first
125
116
  assert_equal text, e.content
126
117
 
127
- # TODO(uwe): Simplify when we stop supporting ActiveRecord 3
128
- if ActiveRecord::VERSION::MAJOR >= 4
129
- e.update! content: 'Other binary content'
130
- else
131
- e.update_attributes! content: 'Other binary content'
132
- end
133
- # ODOT
118
+ e.update! content: 'Other binary content'
134
119
  end
135
120
 
136
121
  def test_on
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uwe Kubosch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-08 00:00:00.000000000 Z
11
+ date: 2019-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.1'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '6'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.1'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6'
@@ -100,6 +100,34 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-performance
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-rails
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
103
131
  - !ruby/object:Gem::Dependency
104
132
  name: simplecov
105
133
  requirement: !ruby/object:Gem::Requirement
@@ -132,18 +160,13 @@ files:
132
160
  - README.md
133
161
  - Rakefile
134
162
  - activerecord-time.gemspec
135
- - gemfiles/ar42.gemfile
136
- - gemfiles/ar42.gemfile.lock
137
- - gemfiles/ar50.gemfile
138
- - gemfiles/ar50.gemfile.lock
139
163
  - gemfiles/ar51.gemfile
140
164
  - gemfiles/ar51.gemfile.lock
141
165
  - gemfiles/ar52.gemfile
142
166
  - gemfiles/ar52.gemfile.lock
143
167
  - gemfiles/common.gemfile
144
168
  - lib/activerecord-time.rb
145
- - lib/activerecord-time/extension_4_2.rb
146
- - lib/activerecord-time/extension_5_0.rb
169
+ - lib/activerecord-time/extension.rb
147
170
  - lib/activerecord-time/version.rb
148
171
  - lib/time_of_day.rb
149
172
  - lib/time_of_day/core_ext.rb
@@ -164,15 +187,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
187
  requirements:
165
188
  - - ">="
166
189
  - !ruby/object:Gem::Version
167
- version: '2.2'
190
+ version: '2.4'
168
191
  required_rubygems_version: !ruby/object:Gem::Requirement
169
192
  requirements:
170
193
  - - ">="
171
194
  - !ruby/object:Gem::Version
172
195
  version: '0'
173
196
  requirements: []
174
- rubyforge_project:
175
- rubygems_version: 2.6.14.1
197
+ rubygems_version: 3.0.3
176
198
  signing_key:
177
199
  specification_version: 4
178
200
  summary: A handler for storing TimeOfDay objects in ActiveRecord objects as sql time
@@ -1,3 +0,0 @@
1
- eval File.read("#{File.dirname __FILE__}/common.gemfile")
2
-
3
- gem 'activerecord', '~>4.2.3'
@@ -1,77 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- activemodel (4.2.10)
5
- activesupport (= 4.2.10)
6
- builder (~> 3.1)
7
- activerecord (4.2.10)
8
- activemodel (= 4.2.10)
9
- activesupport (= 4.2.10)
10
- arel (~> 6.0)
11
- activerecord-jdbc-adapter (50.0)
12
- activerecord (>= 2.2)
13
- activerecord-jdbcderby-adapter (0.8.2)
14
- activerecord-jdbc-adapter (>= 0.8.2)
15
- jdbc-derby (>= 10.3.2.1)
16
- activerecord-jdbcpostgresql-adapter (50.0)
17
- activerecord-jdbc-adapter (~> 50.0)
18
- jdbc-postgres (>= 9.4, < 43)
19
- activerecord-jdbcsqlite3-adapter (50.0)
20
- activerecord-jdbc-adapter (~> 50.0)
21
- jdbc-sqlite3 (~> 3.8, < 3.30)
22
- activesupport (4.2.10)
23
- i18n (~> 0.7)
24
- minitest (~> 5.1)
25
- thread_safe (~> 0.3, >= 0.3.4)
26
- tzinfo (~> 1.1)
27
- ansi (1.5.0)
28
- arel (6.0.4)
29
- builder (3.2.3)
30
- concurrent-ruby (1.0.5)
31
- concurrent-ruby (1.0.5-java)
32
- docile (1.3.0)
33
- i18n (0.9.5)
34
- concurrent-ruby (~> 1.0)
35
- jdbc-derby (10.12.1.1)
36
- jdbc-postgres (42.1.4)
37
- jdbc-sqlite3 (3.20.1)
38
- json (2.1.0)
39
- json (2.1.0-java)
40
- minitest (5.10.3)
41
- minitest-reporters (1.2.0)
42
- ansi
43
- builder
44
- minitest (>= 5.0)
45
- ruby-progressbar
46
- pg (0.21.0)
47
- rake (12.3.1)
48
- ruby-progressbar (1.9.0)
49
- simplecov (0.16.1)
50
- docile (~> 1.1)
51
- json (>= 1.8, < 3)
52
- simplecov-html (~> 0.10.0)
53
- simplecov-html (0.10.2)
54
- sqlite3 (1.3.13)
55
- thread_safe (0.3.6)
56
- thread_safe (0.3.6-java)
57
- tzinfo (1.2.5)
58
- thread_safe (~> 0.1)
59
-
60
- PLATFORMS
61
- java
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord (~> 4.2.3)
66
- activerecord-jdbc-adapter
67
- activerecord-jdbcderby-adapter
68
- activerecord-jdbcpostgresql-adapter
69
- activerecord-jdbcsqlite3-adapter
70
- minitest-reporters
71
- pg (< 1)
72
- rake
73
- simplecov
74
- sqlite3
75
-
76
- BUNDLED WITH
77
- 1.16.1
@@ -1,3 +0,0 @@
1
- eval File.read("#{File.dirname __FILE__}/common.gemfile")
2
-
3
- gem 'activerecord', '~>5.0.1'
@@ -1,76 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- activemodel (5.0.7)
5
- activesupport (= 5.0.7)
6
- activerecord (5.0.7)
7
- activemodel (= 5.0.7)
8
- activesupport (= 5.0.7)
9
- arel (~> 7.0)
10
- activerecord-jdbc-adapter (50.0)
11
- activerecord (>= 2.2)
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 (50.0)
16
- activerecord-jdbc-adapter (~> 50.0)
17
- jdbc-postgres (>= 9.4, < 43)
18
- activerecord-jdbcsqlite3-adapter (50.0)
19
- activerecord-jdbc-adapter (~> 50.0)
20
- jdbc-sqlite3 (~> 3.8, < 3.30)
21
- activesupport (5.0.7)
22
- concurrent-ruby (~> 1.0, >= 1.0.2)
23
- i18n (>= 0.7, < 2)
24
- minitest (~> 5.1)
25
- tzinfo (~> 1.1)
26
- ansi (1.5.0)
27
- arel (7.1.4)
28
- builder (3.2.3)
29
- concurrent-ruby (1.0.5)
30
- concurrent-ruby (1.0.5-java)
31
- docile (1.3.0)
32
- i18n (1.0.1)
33
- concurrent-ruby (~> 1.0)
34
- jdbc-derby (10.12.1.1)
35
- jdbc-postgres (42.1.4)
36
- jdbc-sqlite3 (3.20.1)
37
- json (2.1.0)
38
- json (2.1.0-java)
39
- minitest (5.10.3)
40
- minitest-reporters (1.2.0)
41
- ansi
42
- builder
43
- minitest (>= 5.0)
44
- ruby-progressbar
45
- pg (0.21.0)
46
- rake (12.3.1)
47
- ruby-progressbar (1.9.0)
48
- simplecov (0.16.1)
49
- docile (~> 1.1)
50
- json (>= 1.8, < 3)
51
- simplecov-html (~> 0.10.0)
52
- simplecov-html (0.10.2)
53
- sqlite3 (1.3.13)
54
- thread_safe (0.3.6)
55
- thread_safe (0.3.6-java)
56
- tzinfo (1.2.5)
57
- thread_safe (~> 0.1)
58
-
59
- PLATFORMS
60
- java
61
- ruby
62
-
63
- DEPENDENCIES
64
- activerecord (~> 5.0.1)
65
- activerecord-jdbc-adapter
66
- activerecord-jdbcderby-adapter
67
- activerecord-jdbcpostgresql-adapter
68
- activerecord-jdbcsqlite3-adapter
69
- minitest-reporters
70
- pg (< 1)
71
- rake
72
- simplecov
73
- sqlite3
74
-
75
- BUNDLED WITH
76
- 1.16.1
@@ -1,31 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module Quoting
4
- def _quote_with_time_of_day(value)
5
- return "'#{value}'" if value.is_a?(TimeOfDay)
6
- _quote_without_time_of_day(value)
7
- end
8
- alias_method_chain :_quote, :time_of_day
9
- def _type_cast_with_time_of_day(value)
10
- return value.to_s if value.is_a?(TimeOfDay)
11
- _type_cast_without_time_of_day(value)
12
- end
13
- alias_method_chain :_type_cast, :time_of_day
14
- end
15
- end
16
- end
17
- module Activerecord
18
- module Time
19
- module TypeCast
20
- private
21
-
22
- def cast_value(value)
23
- return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time)
24
- return value unless value.is_a?(::String)
25
- return if value.empty?
26
- TimeOfDay.parse value
27
- end
28
- end
29
- end
30
- end
31
- ActiveRecord::Type::Time.prepend Activerecord::Time::TypeCast