Class: Scalingo::Endpoint::Collection
Instance Attribute Summary
Attributes included from Base
#api, #prefix
Instance Method Summary
collapse
included
#resources
Methods included from Base
#initialize
Instance Method Details
#all ⇒ Object
Also known as:
to_a
59
60
61
|
# File 'lib/scalingo/endpoint.rb', line 59
def all
get[collection_name].map{|r| resource_class.new(self, r[find_by], r)}
end
|
#collection_name ⇒ Object
72
73
74
|
# File 'lib/scalingo/endpoint.rb', line 72
def collection_name
@collection_name ||= self.class.name.underscore.split('/').last
end
|
#each ⇒ Object
64
65
66
|
# File 'lib/scalingo/endpoint.rb', line 64
def each
block_given? ? all.each(&Proc.new) : all.each
end
|
#find(id) ⇒ Object
68
69
70
|
# File 'lib/scalingo/endpoint.rb', line 68
def find(id)
detect{|r| r[find_by] == id}
end
|
#find_by ⇒ Object
84
85
86
|
# File 'lib/scalingo/endpoint.rb', line 84
def find_by
'id'
end
|
#resource_class ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/scalingo/endpoint.rb', line 76
def resource_class
@resource_class ||= begin
Scalingo::Endpoint.const_get(self.class.name.singularize.split('::').last)
rescue
Resource
end
end
|