Class: Braintree::ResourceCollection
- Inherits:
-
Object
- Object
- Braintree::ResourceCollection
- Includes:
- Enumerable
- Defined in:
- lib/braintree/resource_collection.rb
Overview
:nodoc:
Instance Method Summary (collapse)
-
- (Object) each(&block)
Yields each item.
- - (Boolean) empty?
-
- (Object) first
Returns the first item in the collection or nil if the collection is empty.
-
- (ResourceCollection) initialize(response, &block)
constructor
:nodoc:.
-
- (Object) maximum_size
Only the maximum size of a resource collection can be determined since the data on the server can change while fetching blocks of results for iteration.
Constructor Details
- (ResourceCollection) initialize(response, &block)
:nodoc:
5 6 7 8 9 |
# File 'lib/braintree/resource_collection.rb', line 5 def initialize(response, &block) # :nodoc: @ids = Util.extract_attribute_as_array(response[:search_results], :ids) @page_size = response[:search_results][:page_size] @paging_block = block end |
Instance Method Details
- (Object) each(&block)
Yields each item
12 13 14 15 16 17 |
# File 'lib/braintree/resource_collection.rb', line 12 def each(&block) @ids.each_slice(@page_size) do |page_of_ids| resources = @paging_block.call(page_of_ids) resources.each(&block) end end |
- (Boolean) empty?
19 20 21 |
# File 'lib/braintree/resource_collection.rb', line 19 def empty? @ids.empty? end |
- (Object) first
Returns the first item in the collection or nil if the collection is empty
24 25 26 |
# File 'lib/braintree/resource_collection.rb', line 24 def first @paging_block.call([@ids.first]).first end |
- (Object) maximum_size
Only the maximum size of a resource collection can be determined since the data on the server can change while fetching blocks of results for iteration. For example, customers can be deleted while iterating, so the number of results iterated over may be less than the maximum_size. In general, this method should be avoided.
31 32 33 |
# File 'lib/braintree/resource_collection.rb', line 31 def maximum_size @ids.size end |