-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coercing of nested arrays #2054
Conversation
It is a regression which was introduced after migrating to DryTypes. Now, it is again possible to define an array of arrays as a type. params do requires :skills, type: Array[[String]] end
@@ -18,26 +18,27 @@ def initialize(type, strict = false) | |||
super | |||
|
|||
@coercer = scope::Array | |||
@elem_coercer = PrimitiveCoercer.new(type.first, strict) | |||
@nested = type.first.is_a?(Array) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array or any kind of enumerable? Sets of sets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, see my nits, but feel free to merge as is
class << self | ||
def inherited(klass) | ||
# share the hash with classes, so inheritors could will it | ||
klass.instance_variable_set(:@collection_coercers, collection_coercers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels dirty. Maybe we can add a coercers=
method?
expect(subject.call([%w[10 20]])).to eq([Set[10, 20]]) | ||
expect(subject.call([['10'], ['20']])).to eq([Set[10], Set[20]]) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test with one more level of nesting?
Can I do a set of arrays?
@dblock thanks for the quick review 👍 I've improved the design 😊 We can avoid sharing any structure with inheritors. |
Better. |
It is a regression which was introduced after migrating to DryTypes. Now, it is again possible to define an array of arrays as a type.
Fixes #2041