Class: Contentful::Array
- Inherits:
-
BaseResource
- Object
- BaseResource
- Contentful::Array
- Includes:
- ArrayLike
- Defined in:
- lib/contentful/array.rb
Overview
Note:
It also provides an #each method and includes Ruby's Enumerable module (gives you methods like #min, #first, etc)
Resource Class for Arrays (e.g. search results)
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#skip ⇒ Object
readonly
Returns the value of attribute skip.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#initialize(item = nil, configuration = { default_locale: Contentful::Client::DEFAULT_CONFIGURATION[:default_locale] }, endpoint = '') ⇒ Array
constructor
A new instance of Array.
-
#next_page(client = nil) ⇒ Contentful::Array, false
Simplifies pagination.
Methods included from ArrayLike
#[], #array?, #each_item, #empty?, #last, #size
Methods inherited from BaseResource
Constructor Details
#initialize(item = nil, configuration = { default_locale: Contentful::Client::DEFAULT_CONFIGURATION[:default_locale] }, endpoint = '') ⇒ Array
Returns a new instance of Array
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/contentful/array.rb', line 16 def initialize(item = nil, configuration = { default_locale: Contentful::Client::DEFAULT_CONFIGURATION[:default_locale] }, endpoint = '', *) super(item, configuration) @endpoint = endpoint @total = item.fetch('total', nil) @limit = item.fetch('limit', nil) @skip = item.fetch('skip', nil) @items = item.fetch('items', []) end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint
14 15 16 |
# File 'lib/contentful/array.rb', line 14 def endpoint @endpoint end |
#items ⇒ Object (readonly)
Returns the value of attribute items
14 15 16 |
# File 'lib/contentful/array.rb', line 14 def items @items end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit
14 15 16 |
# File 'lib/contentful/array.rb', line 14 def limit @limit end |
#skip ⇒ Object (readonly)
Returns the value of attribute skip
14 15 16 |
# File 'lib/contentful/array.rb', line 14 def skip @skip end |
#total ⇒ Object (readonly)
Returns the value of attribute total
14 15 16 |
# File 'lib/contentful/array.rb', line 14 def total @total end |
Instance Method Details
#next_page(client = nil) ⇒ Contentful::Array, false
Simplifies pagination
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/contentful/array.rb', line 60 def next_page(client = nil) return false if client.nil? return false if items.first.nil? new_skip = (skip || 0) + (limit || DEFAULT_LIMIT) plurals = { 'Space' => 'spaces', 'ContentType' => 'content_types', 'Entry' => 'entries', 'Asset' => 'assets', 'Locale' => 'locales' } client.public_send(plurals[items.first.type], limit: limit, skip: new_skip) end |