Class: Strava::Api::Pagination
- Inherits:
-
Object
- Object
- Strava::Api::Pagination
- Includes:
- Enumerable, DeepCopyable
- Defined in:
- lib/strava/api/pagination.rb
Overview
Wrapper Class around pagination results which are an Array of Models.
This class exists to provide a way to provide a high-level abstraction, like access to API request/response data (i.e. ratelimits) for paginated results.
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
-
#each {|Object| ... } ⇒ void
Iterates over each item in the paginated collection.
-
#http_response ⇒ Strava::Web::ApiResponse
getter method that calculates on access.
-
#initialize(collection, web_response) ⇒ Pagination
constructor
A new instance of Pagination.
-
#size ⇒ Integer
delegates
sizeto @collection.
Methods included from DeepCopyable
Constructor Details
#initialize(collection, web_response) ⇒ Pagination
Returns a new instance of Pagination.
21 22 23 24 |
# File 'lib/strava/api/pagination.rb', line 21 def initialize(collection, web_response) @collection = collection @web_response = web_response end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates missing methods to the underlying collection.
Allows the Pagination object to respond to array methods by forwarding them to the internal collection array.
67 68 69 |
# File 'lib/strava/api/pagination.rb', line 67 def method_missing(method_symbol, ...) @collection.send(method_symbol, ...) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
15 16 17 |
# File 'lib/strava/api/pagination.rb', line 15 def collection @collection end |
Instance Method Details
#each {|Object| ... } ⇒ void
This method returns an undefined value.
Iterates over each item in the paginated collection.
50 51 52 |
# File 'lib/strava/api/pagination.rb', line 50 def each @collection.each { |c| yield c if block_given? } end |
#http_response ⇒ Strava::Web::ApiResponse
getter method that calculates on access
31 32 33 |
# File 'lib/strava/api/pagination.rb', line 31 def http_response @http_response ||= Strava::Web::ApiResponse.new(deep_copy(@web_response).http_response) end |
#size ⇒ Integer
delegates size to @collection
40 41 42 |
# File 'lib/strava/api/pagination.rb', line 40 def size @collection.size end |