Sha256: 52461323553fd6bd21b821641c0f7187f5fe666e36956b3ff73387a153e6ad67

Contents?: true

Size: 1.06 KB

Versions: 13

Compression:

Stored size: 1.06 KB

Contents

module StorageRoom
  # A container object that contains many models (collections or entries)
  class Array < Resource
    many :resources
            
    # Replaces the objects content with the next page of the array if a next page exists
    def load_next_page!
      if self[:@next_page_url].present?
        reload(self[:@next_page_url]) 
        true
      else
        false
      end
    end
    
    # Replace the Collection with the privious page of elements if there is one
    def load_previous_page!
      if self[:@previous_page_url].present?
        reload(self[:@previous_page_url]) 
        true
      else
        false
      end    
    end
    
    
    # Iterate over all pages
    def each_page(args={})
      begin
        yield(self)
      end while(args[:reverse] == true ? load_previous_page! : load_next_page!)
    end
    
    # Iterate over all resources with pagination
    def each_page_each_resource(args={})
      self.each_page(args) do |page|
        page.resources.each do |item|
          yield(item)
        end
      end
    end
        
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
storage_room-0.3.24 lib/storage_room/array.rb
storage_room-0.3.23 lib/storage_room/array.rb
storage_room-0.3.22 lib/storage_room/array.rb
storage_room-0.3.21 lib/storage_room/array.rb
storage_room-0.3.20 lib/storage_room/array.rb
storage_room-0.3.19 lib/storage_room/array.rb
storage_room-0.3.18 lib/storage_room/array.rb
storage_room-0.3.17 lib/storage_room/array.rb
storage_room-0.3.16 lib/storage_room/array.rb
storage_room-0.3.15 lib/storage_room/array.rb
storage_room-0.3.14 lib/storage_room/array.rb
storage_room-0.3.13 lib/storage_room/array.rb
storage_room-0.3.12 lib/storage_room/array.rb