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
-
#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 ‘size` to @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, *args, &block) ⇒ Object (private)
51 52 53 |
# File 'lib/strava/api/pagination.rb', line 51 def method_missing(method_symbol, *args, &block) @collection.send(method_symbol, *args, &block) 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
45 46 47 |
# File 'lib/strava/api/pagination.rb', line 45 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 34 |
# 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
41 42 43 |
# File 'lib/strava/api/pagination.rb', line 41 def size @collection.size end |