Class: Aptible::Api::Resource
- Inherits:
-
Api
- Object
- Api
- Aptible::Api::Resource
- Defined in:
- lib/aptible/api/resource.rb
Class Method Summary collapse
- .collection_url ⇒ Object
- .find(id) ⇒ Object
- .find_by_url(url) ⇒ Object
-
.has_many(relation) ⇒ Object
rubocop:disable PredicateName.
Class Method Details
.collection_url ⇒ Object
5 6 7 8 9 |
# File 'lib/aptible/api/resource.rb', line 5 def self.collection_url basename = name.split('::').last config = Aptible::Api.configuration config.root_url.chomp('/') + "/#{basename.downcase.pluralize}" end |
.find(id) ⇒ Object
11 12 13 |
# File 'lib/aptible/api/resource.rb', line 11 def self.find(id) find_by_url("#{collection_url}/#{id}") end |
.find_by_url(url) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/aptible/api/resource.rb', line 15 def self.find_by_url(url) # REVIEW: Should exception be raised if return type mismatch? new.find_by_url(url) rescue nil end |
.has_many(relation) ⇒ Object
rubocop:disable PredicateName
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aptible/api/resource.rb', line 23 def self.has_many(relation) define_method relation do get unless loaded if (memoized = instance_variable_get("@#{relation}")) memoized elsif links[relation] instance_variable_set("@#{relation}", links[relation].entries) end end end |