Skip to content
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

Merged
merged 3 commits into from
May 16, 2020
Merged

coercing of nested arrays #2054

merged 3 commits into from
May 16, 2020

Conversation

dnesteryuk
Copy link
Member

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

Fixes #2041

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)
Copy link
Member

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?

Copy link
Member

@dblock dblock left a 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)
Copy link
Member

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
Copy link
Member

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?

@dnesteryuk
Copy link
Member Author

@dblock thanks for the quick review 👍 I've improved the design 😊 We can avoid sharing any structure with inheritors.

@dblock
Copy link
Member

dblock commented May 16, 2020

@dblock thanks for the quick review 👍 I've improved the design 😊 We can avoid sharing any structure with inheritors.

Better.

@dblock dblock merged commit 18ed28c into master May 16, 2020
@dblock dblock mentioned this pull request May 16, 2020
@dnesteryuk dnesteryuk deleted the bugfix/2041 branch May 17, 2020 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array[Array[X]] Error
2 participants