subroutine 3.0.1 → 3.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6530220e9e104f3eb840fc5ad28514e4e9bb29f6831f1c8cefa96e3d511454b
4
- data.tar.gz: 0bfaf68aae3bd5f5887c2da31b3cc1b8f8fe9c8e12b88f1365c03836bd4615cf
3
+ metadata.gz: a2dedf592996ae8331d333379af49033a3f5a3e74a4c8dd8d8cf5fbe7c878258
4
+ data.tar.gz: ab33d0b731a9f28b52e4661fdcb6626d6eda2f2e8883a8f05ecfa2b529f2961a
5
5
  SHA512:
6
- metadata.gz: 2c7e809eac6e059bed7029907f4a153b388d564c0ac93b9dde0397a6ef15c5cb57fe816b2b31fdd4d2547dafbbc8d12d52493aebe61aa550afa6c430f2db820a
7
- data.tar.gz: 74d0b0c8c647e3f97fa0899c18a33fbddf7aa7b88a878f22740cd0edacbaf873f7181a164347b88425c1a891662565433d3e6c5dfd5a35f602b785c9b4f7341c
6
+ metadata.gz: 26617e51aeb874dbabb64ad62add32903ad734014ed09e4b0c59f81829bb9bbf728726ab4c7690d82ce1280967b59507c689a58464c13216ad46df87b99c0ff5
7
+ data.tar.gz: 3a45d5cbac6d68660c875e0c7163b403276b360a7d37efb86199d2b593c04876060e6f83b99cef3e0dd2c144cba2c75c11a2eeb51a17253bfff49cb6657c55c7
@@ -4,9 +4,11 @@ require 'date'
4
4
  require 'time'
5
5
  require 'bigdecimal'
6
6
  require 'securerandom'
7
+ require 'active_support/core_ext/object/acts_like'
7
8
  require 'active_support/core_ext/object/blank'
8
9
  require 'active_support/core_ext/object/try'
9
10
  require 'active_support/core_ext/array/wrap'
11
+ require 'active_support/core_ext/time/acts_like'
10
12
 
11
13
  module Subroutine
12
14
  module TypeCaster
@@ -86,7 +88,7 @@ end
86
88
  end
87
89
 
88
90
  ::Subroutine::TypeCaster.register :boolean, :bool do |value, _options = {}|
89
- !!(String(value) =~ /^(yes|true|1|ok)$/)
91
+ !!(String(value) =~ /^(yes|true|1|ok)$/i)
90
92
  end
91
93
 
92
94
  ::Subroutine::TypeCaster.register :iso_date do |value, _options = {}|
@@ -118,7 +120,11 @@ end
118
120
  ::Subroutine::TypeCaster.register :time, :timestamp, :datetime do |value, _options = {}|
119
121
  next nil unless value.present?
120
122
 
121
- ::Time.parse(String(value))
123
+ if value.try(:acts_like?, :time)
124
+ value
125
+ else
126
+ ::Time.parse(String(value))
127
+ end
122
128
  end
123
129
 
124
130
  ::Subroutine::TypeCaster.register :hash, :object, :hashmap, :dict do |value, _options = {}|
@@ -4,7 +4,7 @@ module Subroutine
4
4
 
5
5
  MAJOR = 3
6
6
  MINOR = 0
7
- PATCH = 1
7
+ PATCH = 3
8
8
  PRE = nil
9
9
 
10
10
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
@@ -96,15 +96,45 @@ module Subroutine
96
96
  op.boolean_input = 'no'
97
97
  assert_equal false, op.boolean_input
98
98
 
99
+ op.boolean_input = 'Yes'
100
+ assert_equal true, op.boolean_input
101
+
102
+ op.boolean_input = 'No'
103
+ assert_equal false, op.boolean_input
104
+
105
+ op.boolean_input = 'YES'
106
+ assert_equal true, op.boolean_input
107
+
108
+ op.boolean_input = 'NO'
109
+ assert_equal false, op.boolean_input
110
+
99
111
  op.boolean_input = 'true'
100
112
  assert_equal true, op.boolean_input
101
113
 
102
114
  op.boolean_input = 'false'
103
115
  assert_equal false, op.boolean_input
104
116
 
117
+ op.boolean_input = 'True'
118
+ assert_equal true, op.boolean_input
119
+
120
+ op.boolean_input = 'False'
121
+ assert_equal false, op.boolean_input
122
+
123
+ op.boolean_input = 'TRUE'
124
+ assert_equal true, op.boolean_input
125
+
126
+ op.boolean_input = 'FALSE'
127
+ assert_equal false, op.boolean_input
128
+
105
129
  op.boolean_input = 'ok'
106
130
  assert_equal true, op.boolean_input
107
131
 
132
+ op.boolean_input = 'OK'
133
+ assert_equal true, op.boolean_input
134
+
135
+ op.boolean_input = 'Ok'
136
+ assert_equal true, op.boolean_input
137
+
108
138
  op.boolean_input = ''
109
139
  assert_equal false, op.boolean_input
110
140
 
@@ -226,7 +256,7 @@ module Subroutine
226
256
  assert_equal 0, op.time_input.min
227
257
  assert_equal 0, op.time_input.sec
228
258
 
229
- op.time_input = '2023-05-05T10:00:30Z'
259
+ op.time_input = '2023-05-05T10:00:30.123456Z'
230
260
  assert_equal ::Time, op.time_input.class
231
261
  refute_equal ::DateTime, op.time_input.class
232
262
 
@@ -236,6 +266,12 @@ module Subroutine
236
266
  assert_equal 10, op.time_input.hour
237
267
  assert_equal 0, op.time_input.min
238
268
  assert_equal 30, op.time_input.sec
269
+ assert_equal 123456, op.time_input.usec
270
+
271
+ time = Time.at(1678741605.123456)
272
+ op.time_input = time
273
+ assert_equal time, op.time_input
274
+ assert_equal time.object_id, op.time_input.object_id
239
275
  end
240
276
 
241
277
  def test_iso_date_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.1
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2024-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0'
223
223
  requirements: []
224
- rubygems_version: 3.4.10
224
+ rubygems_version: 3.4.19
225
225
  signing_key:
226
226
  specification_version: 4
227
227
  summary: Feature-driven operation objects.