Class: StorageRoom::Array
- Defined in:
- lib/storage_room/array.rb
Overview
A container object that contains many models (collections or entries)
Instance Method Summary collapse
-
#each_page(args = {}) ⇒ Object
Iterate over all pages.
-
#each_page_each_resource(args = {}) ⇒ Object
Iterate over all resources with pagination.
-
#load_next_page! ⇒ Object
Replaces the objects content with the next page of the array if a next page exists.
-
#load_previous_page! ⇒ Object
Replace the Collection with the privious page of elements if there is one.
Methods inherited from Resource
handle_critical_response_errors, #loaded?, meta_data?, #reload
Methods included from Plugins
Methods included from Accessors
#[], #as_json, #attributes, #attributes=, #eql?, #hash, #initialize, #inspect, #loaded?, #proxy?, #reset!, #response_data, #response_data=, #set_from_response_data, #to_hash
Instance Method Details
#each_page(args = {}) ⇒ Object
Iterate over all pages
28 29 30 31 32 |
# File 'lib/storage_room/array.rb', line 28 def each_page(args={}) begin yield(self) end while(args[:reverse] == true ? load_previous_page! : load_next_page!) end |
#each_page_each_resource(args = {}) ⇒ Object
Iterate over all resources with pagination
35 36 37 38 39 40 41 |
# File 'lib/storage_room/array.rb', line 35 def each_page_each_resource(args={}) self.each_page(args) do |page| page.resources.each do |item| yield(item) end end end |
#load_next_page! ⇒ Object
Replaces the objects content with the next page of the array if a next page exists
7 8 9 10 11 12 13 14 |
# File 'lib/storage_room/array.rb', line 7 def load_next_page! if self[:@next_page_url].present? reload(self[:@next_page_url]) true else false end end |
#load_previous_page! ⇒ Object
Replace the Collection with the privious page of elements if there is one
17 18 19 20 21 22 23 24 |
# File 'lib/storage_room/array.rb', line 17 def load_previous_page! if self[:@previous_page_url].present? reload(self[:@previous_page_url]) true else false end end |