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, #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



61
62
63
# File 'lib/scalingo/endpoint.rb', line 61

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

#collection_nameObject



74
75
76
# File 'lib/scalingo/endpoint.rb', line 74

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

#eachObject



66
67
68
# File 'lib/scalingo/endpoint.rb', line 66

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

#find(id) ⇒ Object



70
71
72
# File 'lib/scalingo/endpoint.rb', line 70

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

#find_byObject



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

def find_by
  'id'
end

#resource_classObject



78
79
80
81
82
83
84
# File 'lib/scalingo/endpoint.rb', line 78

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