class Fog::Collection

Fog::Collection

Attributes

service[R]

Public Class Methods

model(new_model = nil) click to toggle source
# File lib/fog/core/collection.rb, line 36
def self.model(new_model = nil)
  if new_model.nil?
    @model
  else
    @model = new_model
  end
end
new(attributes = {}) click to toggle source

Creates a new Fog::Collection based around the passed service

@param [Hash] attributes @option attributes [Fog::Service] service Instance of a service

@return [Fog::Collection]

# File lib/fog/core/collection.rb, line 65
def initialize(attributes = {})
  @service = attributes.delete(:service)
  @loaded = false
  merge_attributes(attributes)
end

Public Instance Methods

clear() click to toggle source
Calls superclass method
# File lib/fog/core/collection.rb, line 44
def clear
  @loaded = super
end
create(attributes = {}) click to toggle source
# File lib/fog/core/collection.rb, line 48
def create(attributes = {})
  object = new(attributes)
  object.save
  object
end
destroy(identity) click to toggle source
# File lib/fog/core/collection.rb, line 54
def destroy(identity)
  new(:identity => identity).destroy
end
inspect() click to toggle source
# File lib/fog/core/collection.rb, line 71
def inspect
  Fog::Formatador.format(self)
end
load(objects) click to toggle source
# File lib/fog/core/collection.rb, line 75
def load(objects)
  clear && objects.each { |object| self << new(object) }
  self
end
model() click to toggle source
# File lib/fog/core/collection.rb, line 80
def model
  self.class.instance_variable_get("@model")
end
new(attributes = {}) click to toggle source
# File lib/fog/core/collection.rb, line 84
def new(attributes = {})
  unless attributes.is_a?(::Hash)
    raise ArgumentError, "Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"
  end
  model.new(
    {
      :collection => self,
      :service => service
    }.merge(attributes)
  )
end
reload() click to toggle source
# File lib/fog/core/collection.rb, line 96
def reload
  clear && lazy_load
  self
end
table(attributes = nil) click to toggle source
# File lib/fog/core/collection.rb, line 101
def table(attributes = nil)
  Fog::Formatador.display_table(map(&:attributes), attributes)
end
to_json(_options = {}) click to toggle source
# File lib/fog/core/collection.rb, line 105
def to_json(_options = {})
  Fog::JSON.encode(map(&:attributes))
end

Private Instance Methods

lazy_load() click to toggle source
# File lib/fog/core/collection.rb, line 111
def lazy_load
  all
end