subroutine 4.1.4 → 4.1.5
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 +4 -4
- data/lib/subroutine/type_caster.rb +11 -15
- data/lib/subroutine/version.rb +1 -1
- data/lib/subroutine.rb +11 -0
- data/test/subroutine/type_caster_test.rb +17 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12ff37dae5fd328aaa0299e09ff2fe4827b98a3f59e0b4b6545a4b1176f834cf
|
4
|
+
data.tar.gz: 95609b587580e37a859ca906dc9a7c767dc589a32a58a3a86f9c2b9e70a2c27c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d29b8e4f5cb1511974c339f28552f85da427bd146a273783abab7951a059b402d96e3fb53c52f8aa64d50bc1f174b103f5c183b4b35f94fc7f570de8e2330ba
|
7
|
+
data.tar.gz: c144a73f6ff5dd51ad70ae3b1bc3d11aee020e9bc78a69805c40f1809e4597a9d51470d6974ef3259ac5975cde33d1c2beb5437985be12c116493d135b1e23a6
|
@@ -4,6 +4,7 @@ require 'date'
|
|
4
4
|
require 'time'
|
5
5
|
require 'bigdecimal'
|
6
6
|
require 'securerandom'
|
7
|
+
require 'active_support/json'
|
7
8
|
require 'active_support/core_ext/date_time/acts_like'
|
8
9
|
require 'active_support/core_ext/date_time/calculations'
|
9
10
|
require 'active_support/core_ext/object/acts_like'
|
@@ -111,7 +112,7 @@ end
|
|
111
112
|
t ||= value if value.is_a?(::Time)
|
112
113
|
t ||= value if value.try(:acts_like?, :time)
|
113
114
|
t ||= ::Time.parse(String(value))
|
114
|
-
t.utc.iso8601
|
115
|
+
t.utc.iso8601(::ActiveSupport::JSON::Encoding.time_precision)
|
115
116
|
end
|
116
117
|
|
117
118
|
::Subroutine::TypeCaster.register :date do |value, _options = {}|
|
@@ -123,21 +124,16 @@ end
|
|
123
124
|
::Subroutine::TypeCaster.register :time, :timestamp, :datetime do |value, options = {}|
|
124
125
|
next nil unless value.present?
|
125
126
|
|
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)
|
127
|
+
value = if value.try(:acts_like?, :time)
|
128
|
+
value.to_time
|
129
|
+
else
|
130
|
+
::Time.parse(String(value))
|
140
131
|
end
|
132
|
+
|
133
|
+
# High precision must be opted into. The original implementation is to set usec:0
|
134
|
+
next value if options[:precision] == :high || ::Subroutine.preserve_time_precision?
|
135
|
+
|
136
|
+
value.change(usec: 0)
|
141
137
|
end
|
142
138
|
|
143
139
|
::Subroutine::TypeCaster.register :hash, :object, :hashmap, :dict do |value, _options = {}|
|
data/lib/subroutine/version.rb
CHANGED
data/lib/subroutine.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_model"
|
4
|
+
require "active_support"
|
4
5
|
require "active_support/concern"
|
5
6
|
require "active_support/core_ext/hash/indifferent_access"
|
6
7
|
require "active_support/core_ext/module/redefine_method"
|
@@ -33,4 +34,14 @@ module Subroutine
|
|
33
34
|
@inheritable_field_options ||= %i[mass_assignable field_reader field_writer groups aka]
|
34
35
|
end
|
35
36
|
|
37
|
+
def self.preserve_time_precision=(bool)
|
38
|
+
@preserve_time_precision = !!bool
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.preserve_time_precision?
|
42
|
+
return !!@preserve_time_precision if defined?(@preserve_time_precision)
|
43
|
+
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
36
47
|
end
|
@@ -344,6 +344,20 @@ module Subroutine
|
|
344
344
|
assert_equal 0, op.time_input.usec
|
345
345
|
end
|
346
346
|
|
347
|
+
def test_time_inputs__with_preserve_time_precision
|
348
|
+
Subroutine.stubs(:preserve_time_precision?).returns(true)
|
349
|
+
|
350
|
+
time = Time.at(1678741605.123456).utc
|
351
|
+
op.time_input = time
|
352
|
+
assert_equal 2023, op.time_input.year
|
353
|
+
assert_equal 3, op.time_input.month
|
354
|
+
assert_equal 13, op.time_input.day
|
355
|
+
assert_equal 21, op.time_input.hour
|
356
|
+
assert_equal 6, op.time_input.min
|
357
|
+
assert_equal 45, op.time_input.sec
|
358
|
+
assert_equal 123456, op.time_input.usec
|
359
|
+
end
|
360
|
+
|
347
361
|
def test_time_inputs__with_high_precision
|
348
362
|
op.precise_time_input = nil
|
349
363
|
assert_nil op.precise_time_input
|
@@ -438,11 +452,11 @@ module Subroutine
|
|
438
452
|
|
439
453
|
op.iso_time_input = '2022-12-22T10:30:24Z'
|
440
454
|
assert_equal ::String, op.iso_time_input.class
|
441
|
-
assert_equal '2022-12-22T10:30:
|
455
|
+
assert_equal '2022-12-22T10:30:24.000Z', op.iso_time_input
|
442
456
|
|
443
|
-
op.iso_time_input = Time.parse('2022-12-22T10:30:
|
457
|
+
op.iso_time_input = Time.parse('2022-12-22T10:30:24.123456Z')
|
444
458
|
assert_equal ::String, op.iso_time_input.class
|
445
|
-
assert_equal '2022-12-22T10:30:
|
459
|
+
assert_equal '2022-12-22T10:30:24.123Z', op.iso_time_input
|
446
460
|
end
|
447
461
|
|
448
462
|
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: 4.1.
|
4
|
+
version: 4.1.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
|
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
212
|
- !ruby/object:Gem::Version
|
213
213
|
version: '0'
|
214
214
|
requirements: []
|
215
|
-
rubygems_version: 3.
|
215
|
+
rubygems_version: 3.5.23
|
216
216
|
signing_key:
|
217
217
|
specification_version: 4
|
218
218
|
summary: Feature-driven operation objects.
|