Class: Scalingo::Endpoint::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Scalingo::Endpoint, Base
Defined in:
lib/scalingo/endpoint.rb

Instance Attribute Summary

Attributes included from Base

#api, #auth_api, #prefix

Instance Method Summary collapse

Methods included from Scalingo::Endpoint

included

Methods included from ClassMethods

#resources

Methods included from Base

#initialize

Instance Method Details

#allObject Also known as: to_a



72
73
74
# File 'lib/scalingo/endpoint.rb', line 72

def all
  get[collection_name].map { |r| resource_class.new(self, r[find_by], {}, r) }
end

#collection_nameObject



85
86
87
# File 'lib/scalingo/endpoint.rb', line 85

def collection_name
  @collection_name ||= self.class.name.underscore.split('/').last
end

#eachObject



77
78
79
# File 'lib/scalingo/endpoint.rb', line 77

def each
  block_given? ? all.each(&Proc.new) : all.each
end

#find(id) ⇒ Object



81
82
83
# File 'lib/scalingo/endpoint.rb', line 81

def find(id)
  detect { |r| r[find_by] == id }
end

#find_byObject



97
98
99
# File 'lib/scalingo/endpoint.rb', line 97

def find_by
  'id'
end

#resource_classObject



89
90
91
92
93
94
95
# File 'lib/scalingo/endpoint.rb', line 89

def resource_class
  @resource_class ||= begin
                        Scalingo::Endpoint.const_get(self.class.name.singularize.split('::').last)
                      rescue
                        Resource
                      end
end