Module: Appfirst::Collection
- Included in:
- Appfirst::Client::ServerTags
- Defined in:
- lib/appfirst/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
- #create!(*args) ⇒ Object
- #get(id) ⇒ Object
- #model_request ⇒ Object
- #model_root ⇒ Object
Class Method Details
.included(klass) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/appfirst/collection.rb', line 2 def self.included(klass) klass.attribute :next_link klass.attribute :prev_link klass.attribute :last_link klass.attribute :total_count klass.attribute :url klass.send(:extend, Appfirst::Collection::Attributes) end |
Instance Method Details
#==(comparison_object) ⇒ Object
46 47 48 49 50 |
# File 'lib/appfirst/collection.rb', line 46 def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.is_a?(self.class) && comparison_object.map(&:identity) == self.map(&:identity)) end |
#all(params = {}) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/appfirst/collection.rb', line 52 def all(params={}) params["url"] ||= self.url response = self.connection.send(self.collection_request, params) load_page(response) end |
#collection_request ⇒ Object
42 43 44 |
# File 'lib/appfirst/collection.rb', line 42 def collection_request self.class.instance_variable_get(:@collection_request) end |
#collection_root ⇒ Object
38 39 40 |
# File 'lib/appfirst/collection.rb', line 38 def collection_root self.class.instance_variable_get(:@collection_root) end |
#create!(*args) ⇒ Object
15 16 17 18 |
# File 'lib/appfirst/collection.rb', line 15 def create!(*args) model = self.new(*args) model.save! end |
#get(id) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/appfirst/collection.rb', line 28 def get(id) if data = connection.send(self.model_request, "id" => id).body[self.model_root] new(data) else nil end rescue Appfirst::Response::NotFound nil end |
#model_request ⇒ Object
24 25 26 |
# File 'lib/appfirst/collection.rb', line 24 def model_request self.class.model_request end |
#model_root ⇒ Object
20 21 22 |
# File 'lib/appfirst/collection.rb', line 20 def model_root self.class.model_root end |