activerecord-time 0.22.0 → 1.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: 871778cc70f4d4da9385d3d38e9d8e5b945e459ffe0e78c7e340b8e12f795ef6
4
- data.tar.gz: 9d9dfbc6e0256c8b91db7a788ace40cd9ffd583cd5dda8713907545b776ea97f
3
+ metadata.gz: c8b419c5f843c2bfca043d296c223b5f747d33b9a0d802fc76e8e70f8f3a05ef
4
+ data.tar.gz: 8b0074a1d050a9e5b1d20f9a4ea83b51919ccc2341077077404c1a82c7694565
5
5
  SHA512:
6
- metadata.gz: 9965445d6ca087fe9e860b75be161f3ecf22c949d7c44c5c521e5d50938f8d7cb7f9f15af1972766f753c5b1abe748eae4a51a99d57ef12be786cca5c322a347
7
- data.tar.gz: 6662a72e566791c18d8439685f1202e12a7ed32ac60917cc1aa64384e1de53ea6ed5b89cb73f5091435ebe5656eaeb16c0466eb01d073eccd2196f9adc5c13f3
6
+ metadata.gz: 3f69d39a705f909cda7e37f693c3fd0a4af1c9d86497bd7c2f860722f76279e42acbae675756e9a455d8b79e03749c7264953546e98524a714740790c9cb1b21
7
+ data.tar.gz: ce575b1067e5bc8cadcaa6911552ec8c04c61eb5c9db8d8e3f9dd3226a761c5d67371f580050a8ac8600b11d392ddebf733073d352590bd9186371fc564965c0
@@ -36,18 +36,23 @@ jobs:
36
36
  strategy:
37
37
  fail-fast: false
38
38
  matrix:
39
- # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
40
39
  ruby: [ 3.3, 3.2, 3.1, jruby, truffleruby ]
41
40
  gemfile: [ ar71, ar70 ]
42
41
  adapter: [ postgresql, sqlite3 ]
43
42
  exclude:
44
43
  - ruby: jruby
44
+ gemfile: ar71 # Not released, yet.
45
+ - ruby: jruby
46
+ gemfile: ar70 # Fails, please investigate.
47
+ - ruby: truffleruby
48
+ gemfile: ar71 # Fails, please investigate.
45
49
  - ruby: truffleruby
50
+ gemfile: ar70 # Fails, please investigate.
46
51
  env:
47
52
  ADAPTER: ${{ matrix.adapter }}
48
53
  BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/gems_${{ matrix.gemfile }}.rb
49
54
  steps:
50
- - uses: actions/checkout@v2
55
+ - uses: actions/checkout@v4
51
56
  - uses: ruby/setup-ruby@v1
52
57
  with:
53
58
  ruby-version: ${{ matrix.ruby }}
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module Type
5
+ class Time < ActiveModel::Type::Time
6
+ include Internal::Timezone
7
+
8
+ class Value < DelegateClass(::TimeOfDay) # :nodoc:
9
+ end
10
+
11
+ def map(value)
12
+ value
13
+ end
14
+
15
+ def serialize(value)
16
+ case value = super
17
+ when ::TimeOfDay
18
+ Value.new(value)
19
+ else
20
+ value
21
+ end
22
+ end
23
+
24
+ def serialize_cast_value(value)
25
+ Value.new(value) if value
26
+ end
27
+
28
+ private def cast_value(value)
29
+ return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time)
30
+ return value unless value.is_a?(::String)
31
+ return if value.empty?
32
+
33
+ TimeOfDay._parse(value)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,38 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record/connection_adapters/abstract/quoting'
4
-
5
3
  module Activerecord
6
4
  module Time
7
5
  module Quoting
8
6
  def quote(value)
9
7
  return "'#{value}'" if value.is_a?(TimeOfDay)
10
8
 
11
- super(value)
9
+ super
12
10
  end
13
11
 
14
12
  def type_cast(value)
15
13
  return value.to_s if value.is_a?(TimeOfDay)
16
14
 
17
- super(value)
15
+ super
18
16
  end
19
17
  end
20
18
  end
21
19
  end
22
20
 
23
21
  ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend Activerecord::Time::Quoting
24
-
25
- module Activerecord
26
- module Time
27
- module Casting
28
- private def cast_value(value)
29
- return value.time_of_day if value.is_a?(::DateTime) || value.is_a?(::Time)
30
- return value unless value.is_a?(::String)
31
- return if value.empty?
32
-
33
- TimeOfDay._parse(value)
34
- end
35
- end
36
- end
37
- end
38
- ActiveRecord::Type::Time.prepend Activerecord::Time::Casting
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Activerecord
4
4
  module Time
5
- VERSION = '0.22.0'
5
+ VERSION = '1.0.0'
6
6
  end
7
7
  end
@@ -23,6 +23,8 @@ end
23
23
 
24
24
  class Date
25
25
  def at(time_of_day)
26
+ return if time_of_day.nil?
27
+
26
28
  time_of_day = TimeOfDay.parse(time_of_day) if time_of_day.is_a?(String)
27
29
  zone = Time.zone || Time
28
30
  zone.local(year, month, day, time_of_day.hour, time_of_day.minute, time_of_day.second)
data/matrix_test.rb CHANGED
@@ -6,6 +6,7 @@ system('rubocop --autocorrect-all') || exit(1)
6
6
  update_gemfiles = ARGV.delete('--update')
7
7
 
8
8
  require 'yaml'
9
+ require 'bundler'
9
10
  actions = YAML.safe_load_file('.github/workflows/test.yml')
10
11
 
11
12
  def run_script(ruby, env, gemfile)
@@ -36,7 +37,7 @@ def use_gemfile(ruby, gemfile, update_gemfiles)
36
37
  end
37
38
 
38
39
  def bad_variant?(bad_variants, ruby, gemfile = nil, adapter = nil)
39
- bad_variants.find do |f|
40
+ bad_variants&.find do |f|
40
41
  !(ruby.nil? ^ f['ruby'].nil?) && f['ruby'] == ruby &&
41
42
  !(gemfile.nil? ^ f['gemfile'].nil?) && f['gemfile'] == gemfile &&
42
43
  !(adapter.nil? ^ f['adapter'].nil?) && f['adapter'] == adapter
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.22.0
4
+ version: 1.0.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: 2024-04-28 00:00:00.000000000 Z
11
+ date: 2024-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -129,6 +129,7 @@ files:
129
129
  - gemfiles/common.gemfile
130
130
  - gemfiles/gems_ar70.rb
131
131
  - gemfiles/gems_ar71.rb
132
+ - lib/active_record/type/time.rb
132
133
  - lib/activerecord-time.rb
133
134
  - lib/activerecord-time/extension.rb
134
135
  - lib/activerecord-time/version.rb