subroutine 4.0.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.MD +13 -0
- data/lib/subroutine/fields/configuration.rb +4 -0
- data/lib/subroutine/fields.rb +8 -1
- data/lib/subroutine/version.rb +2 -2
- data/test/subroutine/type_caster_test.rb +28 -0
- data/test/support/ops.rb +1 -0
- 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: 5b099aef955fc06d44e4a9c628f261e15300fe1dca247c4f8ee042be538037a8
|
4
|
+
data.tar.gz: 3879046fc03f34b01c243f8a1cc1630c30075f6c186593509935b4ae1b62d6a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60327bcf9acf93b74b5ff94b45d18c7765830f2c2456481585274b75348b316dca245597f332fe95c54b47d6a91f21de7876c96bdcfb3418d213a38d45f1fbdb
|
7
|
+
data.tar.gz: aa61977d8dec95499096f58d9590a059796d0cfe211f604237cb53ab69bc72ad634515c621ad76b128dea11bfba6acb1d6c82b607c22c8fe3fae74364353a3cc
|
data/CHANGELOG.MD
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## Subroutine 4.1.0
|
2
|
+
|
3
|
+
A field can no opt out of the natural assignment behavior of ActiveSupport::HashWithIndifferentAccess. Top level param groups are still accessible via indifferent access but if a field sets the `bypass_indifferent_assignment` option to `true` the HashWithIndifferentAccess assignment behavior will be bypassed in favor of direct Hash-like assignment.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
class MyOp < Subroutine::Op
|
7
|
+
|
8
|
+
object :some_hash
|
9
|
+
object :some_other_hash, bypass_indifferent_assignment: true
|
10
|
+
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
1
14
|
## Subroutine 4.0.1
|
2
15
|
|
3
16
|
Association fields can now use `find_by()` instead of `find_by!()` by passing a `raise_on_miss: false` option. This places the responsibility on the op to manage nil cases rather than handling RecordNotFound errors.
|
data/lib/subroutine/fields.rb
CHANGED
@@ -186,7 +186,14 @@ module Subroutine
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def set_param_group_value(name, key, value)
|
189
|
-
|
189
|
+
config = get_field_config(key)
|
190
|
+
group = get_param_group(name)
|
191
|
+
|
192
|
+
if config&.bypass_indifferent_assignment?
|
193
|
+
group.regular_writer(group.send(:convert_key, key), value)
|
194
|
+
else
|
195
|
+
group[key.to_sym] = value
|
196
|
+
end
|
190
197
|
end
|
191
198
|
|
192
199
|
def original_params
|
data/lib/subroutine/version.rb
CHANGED
@@ -175,6 +175,34 @@ module Subroutine
|
|
175
175
|
|
176
176
|
op.object_input = { 'foo' => { 'bar' => :baz } }
|
177
177
|
assert_equal({ 'foo' => { 'bar' => :baz } }, op.object_input)
|
178
|
+
|
179
|
+
op.object_input = { foo: "bar" }
|
180
|
+
assert op.object_input.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_hash_inputs_can_opt_out_of_indifferent_access_behavior
|
184
|
+
op.no_indifferent_object_input = nil
|
185
|
+
assert_nil op.no_indifferent_object_input
|
186
|
+
|
187
|
+
op.no_indifferent_object_input = ''
|
188
|
+
assert_equal({}, op.no_indifferent_object_input)
|
189
|
+
|
190
|
+
op.no_indifferent_object_input = [[:a, :b]]
|
191
|
+
assert_equal({ a: :b }, op.no_indifferent_object_input)
|
192
|
+
|
193
|
+
op.no_indifferent_object_input = { foo: "bar" }
|
194
|
+
assert_equal({ foo: "bar" }, op.no_indifferent_object_input)
|
195
|
+
assert op.no_indifferent_object_input.key?(:foo)
|
196
|
+
refute op.no_indifferent_object_input.key?("foo")
|
197
|
+
refute op.no_indifferent_object_input.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
198
|
+
assert op.no_indifferent_object_input.is_a?(Hash)
|
199
|
+
|
200
|
+
op.no_indifferent_object_input = { "foo" => "bar" }
|
201
|
+
assert_equal({ "foo" => "bar" }, op.no_indifferent_object_input)
|
202
|
+
assert op.no_indifferent_object_input.key?("foo")
|
203
|
+
refute op.no_indifferent_object_input.key?(:foo)
|
204
|
+
refute op.no_indifferent_object_input.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
205
|
+
assert op.no_indifferent_object_input.is_a?(Hash)
|
178
206
|
end
|
179
207
|
|
180
208
|
def test_array_inputs
|
data/test/support/ops.rb
CHANGED
@@ -176,6 +176,7 @@ class TypeCastOp < ::Subroutine::Op
|
|
176
176
|
iso_date :iso_date_input
|
177
177
|
iso_time :iso_time_input
|
178
178
|
object :object_input
|
179
|
+
object :no_indifferent_object_input, bypass_indifferent_assignment: true
|
179
180
|
array :array_input, default: "foo"
|
180
181
|
array :type_array_input, of: :integer
|
181
182
|
file :file_input
|
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.0
|
4
|
+
version: 4.1.0
|
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-05-
|
11
|
+
date: 2024-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|