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

Add support for Sequel datasets #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add support for Sequel datasets #189

wants to merge 1 commit into from

Conversation

martijnbleeker
Copy link

Sequel dataset do not support the to_ary implementation.
To add support, check if objects is a list.

Note: nil and Hash both implement to_a but aren't lists themselves.

Fixes #188

Please let me know if this fix is ok.
Do you think only checking nil and Hash is enough?

Sequel dataset do not support the `to_ary` implementation. 
To add support, check if `objects` is a list.

`nil` and `Hash` both implement `to_a` but aren't lists themselves.

Fixes #188
root_element = root_element(:collection_root)
inner = objects.send(collection_method_name).map do |object|
new(object, options.reverse_merge(collection: true)).presented
end
else
objects = { @collection_name => objects } if @present_collection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think storing the method name is strange, or at least not idiomatic. How's this?

ary = if objects.respond_to?(:to_ary)
  objects.to_ary
elsif ! objects.is_a?(Hash) && objects.respond_to?(:to_a) #nil? is redundant here
  objects.to_a
end

if ary && !@present_collection
  root_element = root_element(:collection_root)
  inner = ary.map ...
elsif @present_collection
  objects = { @collection_name => objects }
end

@dblock
Copy link
Member

dblock commented Nov 7, 2015

You also need tests for this to be merged and a CHANGELOG entry, please.

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.

Sequel collection support
2 participants