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 +4 -4
- data/.github/workflows/test.yml +7 -2
- data/lib/active_record/type/time.rb +37 -0
- data/lib/activerecord-time/extension.rb +2 -19
- data/lib/activerecord-time/version.rb +1 -1
- data/lib/time_of_day/core_ext.rb +2 -0
- data/matrix_test.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8b419c5f843c2bfca043d296c223b5f747d33b9a0d802fc76e8e70f8f3a05ef
|
4
|
+
data.tar.gz: 8b0074a1d050a9e5b1d20f9a4ea83b51919ccc2341077077404c1a82c7694565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f69d39a705f909cda7e37f693c3fd0a4af1c9d86497bd7c2f860722f76279e42acbae675756e9a455d8b79e03749c7264953546e98524a714740790c9cb1b21
|
7
|
+
data.tar.gz: ce575b1067e5bc8cadcaa6911552ec8c04c61eb5c9db8d8e3f9dd3226a761c5d67371f580050a8ac8600b11d392ddebf733073d352590bd9186371fc564965c0
|
data/.github/workflows/test.yml
CHANGED
@@ -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@
|
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
|
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
|
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
|
data/lib/time_of_day/core_ext.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|