Class: Strava::Api::Pagination

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from DeepCopyable

#deep_copy

Constructor Details

#initialize(collection, web_response) ⇒ Pagination

Returns a new instance of Pagination.

Parameters:



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.

Parameters:

  • method_symbol (Symbol)

    The method name to forward

  • args (Array)

    Arguments to pass to the method

Returns:

  • (Object)

    Result from the delegated method



67
68
69
# File 'lib/strava/api/pagination.rb', line 67

def method_missing(method_symbol, ...)
  @collection.send(method_symbol, ...)
end

Instance Attribute Details

#collectionObject (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.

Yields:

  • (Object)

    Yields each item in the collection



50
51
52
# File 'lib/strava/api/pagination.rb', line 50

def each
  @collection.each { |c| yield c if block_given? }
end

#http_responseStrava::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

#sizeInteger

delegates size to @collection

Returns:

  • (Integer)


40
41
42
# File 'lib/strava/api/pagination.rb', line 40

def size
  @collection.size
end