Module: Imgur::PagedCollection
- Included in:
- Client::Accounts, Client::Albums, Client::BasicResponses, Client::Images
- Defined in:
- lib/imgur/paged_collection.rb
Defined Under Namespace
Modules: Attributes
Class Method Summary collapse
Instance Method Summary collapse
- #==(comparison_object) ⇒ Object
- #all(params = {}) ⇒ Object
- #collection_request ⇒ Object
- #collection_root ⇒ Object
- #last_page ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
Class Method Details
.included(klass) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/imgur/paged_collection.rb', line 2 def self.included(klass) klass.attribute :next_link klass.attribute :prev_link klass.attribute :last_link klass.send(:extend, Imgur::PagedCollection::Attributes) end |
Instance Method Details
#==(comparison_object) ⇒ Object
39 40 41 42 43 |
# File 'lib/imgur/paged_collection.rb', line 39 def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.is_a?(self.class) && comparison_object.map(&:identity) == self.map(&:identity)) end |
#all(params = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/imgur/paged_collection.rb', line 45 def all(params={}) response = connection.send(self.collection_request, params) collection = self.clone.load(response.body[self.collection_root]) end |
#collection_request ⇒ Object
23 24 25 |
# File 'lib/imgur/paged_collection.rb', line 23 def collection_request self.class.instance_variable_get(:@collection_request) end |
#collection_root ⇒ Object
19 20 21 |
# File 'lib/imgur/paged_collection.rb', line 19 def collection_root self.class.instance_variable_get(:@collection_root) end |
#last_page ⇒ Object
35 36 37 |
# File 'lib/imgur/paged_collection.rb', line 35 def last_page all("url" => self.last_link) end |
#next_page ⇒ Object
27 28 29 |
# File 'lib/imgur/paged_collection.rb', line 27 def next_page all("url" => self.next_link) if self.next_link end |
#previous_page ⇒ Object
31 32 33 |
# File 'lib/imgur/paged_collection.rb', line 31 def previous_page all("url" => self.prev_link) if self.prev_link end |