subroutine 3.0.4 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subroutine/type_caster.rb +12 -15
- data/lib/subroutine/version.rb +1 -1
- data/lib/subroutine.rb +14 -0
- data/test/subroutine/type_caster_test.rb +17 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7441c613353cda046900b7165d787576d3cb757943496fb7b4ccc65a9f5faf1
|
4
|
+
data.tar.gz: b154f7ab48dc32c391be450bc684ee34d59451d6e327d90f463654d53e8f0a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9da5a1f35f9888ebc970e23c60e53871258d837767b6baf3597fb216c64eca039171d993f4abc8c02627b678623e47df35defe5a79799a6c166ff7aebc2cb712
|
7
|
+
data.tar.gz: 5df7cc84df8ec5b19f60f9101fb66abeee95b578b474d956d378857132a60881a039c55ddecc4b8e6405b1ef9c95fb69f5b3d2d3ffc3fd5cb02bdce0aba8da4d
|
@@ -4,6 +4,8 @@ require 'date'
|
|
4
4
|
require 'time'
|
5
5
|
require 'bigdecimal'
|
6
6
|
require 'securerandom'
|
7
|
+
require 'active_support'
|
8
|
+
require 'active_support/json'
|
7
9
|
require 'active_support/core_ext/date_time/acts_like'
|
8
10
|
require 'active_support/core_ext/date_time/calculations'
|
9
11
|
require 'active_support/core_ext/object/acts_like'
|
@@ -111,7 +113,7 @@ end
|
|
111
113
|
t ||= value if value.is_a?(::Time)
|
112
114
|
t ||= value if value.try(:acts_like?, :time)
|
113
115
|
t ||= ::Time.parse(String(value))
|
114
|
-
t.utc.iso8601
|
116
|
+
t.utc.iso8601(::ActiveSupport::JSON::Encoding.time_precision)
|
115
117
|
end
|
116
118
|
|
117
119
|
::Subroutine::TypeCaster.register :date do |value, _options = {}|
|
@@ -123,21 +125,16 @@ end
|
|
123
125
|
::Subroutine::TypeCaster.register :time, :timestamp, :datetime do |value, options = {}|
|
124
126
|
next nil unless value.present?
|
125
127
|
|
126
|
-
if
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
::Time.parse(String(value))
|
131
|
-
end
|
132
|
-
else # precision == :seconds
|
133
|
-
time = if value.try(:acts_like?, :time)
|
134
|
-
value.to_time
|
135
|
-
else
|
136
|
-
::Time.parse(String(value))
|
137
|
-
end
|
138
|
-
|
139
|
-
time.change(usec: 0)
|
128
|
+
value = if value.try(:acts_like?, :time)
|
129
|
+
value.to_time
|
130
|
+
else
|
131
|
+
::Time.parse(String(value))
|
140
132
|
end
|
133
|
+
|
134
|
+
# High precision must be opted into. The original implementation is to set usec:0
|
135
|
+
next value if options[:precision] == :high || ::Subroutine.preserve_time_precision?
|
136
|
+
|
137
|
+
value.change(usec: 0)
|
141
138
|
end
|
142
139
|
|
143
140
|
::Subroutine::TypeCaster.register :hash, :object, :hashmap, :dict do |value, _options = {}|
|
data/lib/subroutine/version.rb
CHANGED
data/lib/subroutine.rb
CHANGED
@@ -3,3 +3,17 @@
|
|
3
3
|
require "subroutine/version"
|
4
4
|
require "subroutine/fields"
|
5
5
|
require "subroutine/op"
|
6
|
+
|
7
|
+
module Subroutine
|
8
|
+
|
9
|
+
def self.preserve_time_precision=(bool)
|
10
|
+
@preserve_time_precision = !!bool
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.preserve_time_precision?
|
14
|
+
return !!@preserve_time_precision if defined?(@preserve_time_precision)
|
15
|
+
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -316,6 +316,20 @@ module Subroutine
|
|
316
316
|
assert_equal 0, op.time_input.usec
|
317
317
|
end
|
318
318
|
|
319
|
+
def test_time_inputs__with_preserve_time_precision
|
320
|
+
Subroutine.stubs(:preserve_time_precision?).returns(true)
|
321
|
+
|
322
|
+
time = Time.at(1678741605.123456).utc
|
323
|
+
op.time_input = time
|
324
|
+
assert_equal 2023, op.time_input.year
|
325
|
+
assert_equal 3, op.time_input.month
|
326
|
+
assert_equal 13, op.time_input.day
|
327
|
+
assert_equal 21, op.time_input.hour
|
328
|
+
assert_equal 6, op.time_input.min
|
329
|
+
assert_equal 45, op.time_input.sec
|
330
|
+
assert_equal 123456, op.time_input.usec
|
331
|
+
end
|
332
|
+
|
319
333
|
def test_time_inputs__with_high_precision
|
320
334
|
op.precise_time_input = nil
|
321
335
|
assert_nil op.precise_time_input
|
@@ -410,11 +424,11 @@ module Subroutine
|
|
410
424
|
|
411
425
|
op.iso_time_input = '2022-12-22T10:30:24Z'
|
412
426
|
assert_equal ::String, op.iso_time_input.class
|
413
|
-
assert_equal '2022-12-22T10:30:
|
427
|
+
assert_equal '2022-12-22T10:30:24.000Z', op.iso_time_input
|
414
428
|
|
415
|
-
op.iso_time_input = Time.parse('2022-12-22T10:30:
|
429
|
+
op.iso_time_input = Time.parse('2022-12-22T10:30:24.123456Z')
|
416
430
|
assert_equal ::String, op.iso_time_input.class
|
417
|
-
assert_equal '2022-12-22T10:30:
|
431
|
+
assert_equal '2022-12-22T10:30:24.123Z', op.iso_time_input
|
418
432
|
end
|
419
433
|
|
420
434
|
def test_file_inputs
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subroutine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|