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

collection method load_records should pass parameters #83

Open
leklund opened this issue Feb 6, 2018 · 1 comment
Open

collection method load_records should pass parameters #83

leklund opened this issue Feb 6, 2018 · 1 comment

Comments

@leklund
Copy link
Contributor

leklund commented Feb 6, 2018

When loading a collection if you do

cistern.things(page: 1, per_page: 3).each {|thing| thing.call }

the parameters won't get passed through to the all call that the load_records method calls.

It works if you call

cistern.things.all(page: 1, per_page: 3).each {|thing| thing.call }
@lanej
Copy link
Owner

lanej commented Jul 26, 2018

Depends on how you structure the implementation of your collection. If you had page and per_page attributes on the collection (recommended), then

class Foo::Things < Foo::Collection
  attribute :page
  attribute :per_page

  def all
	load get_things(page: page, per_page: per_page).data
  end
end

Foo.new.things(page: 1, per_page: 3).each {|thing| thing.call } # works

The following works when you consider #all() with arguments

class Foo::Things < Foo::Collection
  def all(page:, per_page:)
	load get_things(page: page, per_page: per_page).data
  end
end

Foo.new.things(page: 1, per_page: 3).each {|thing| thing.call } # does not work

Foo.new.things.all(page: 1, per_page: 3).each {|thing| thing.call } # works

@lanej lanej closed this as completed Jul 26, 2018
@lanej lanej reopened this Jul 26, 2018
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

No branches or pull requests

2 participants