cistern
cistern copied to clipboard
collection method `load_records` should pass parameters
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 }
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