Parent

Class/Module Index [+]

Quicksearch

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 68
def initialize(attributes = {})
  @service = attributes.delete(:service)
  @loaded = false
  merge_attributes(attributes)
end

Public Instance Methods

clear() click to toggle source
# File lib/fog/core/collection.rb, line 45
def clear
  @loaded = true
  super
end
create(attributes = {}) click to toggle source
# File lib/fog/core/collection.rb, line 50
def create(attributes = {})
  object = new(attributes)
  object.save
  object
end
destroy(identity) click to toggle source
# File lib/fog/core/collection.rb, line 56
def destroy(identity)
  object = new(:identity => identity)
  object.destroy
end
inspect() click to toggle source
# File lib/fog/core/collection.rb, line 76
def inspect
  Thread.current[:formatador] ||= Formatador.new
  data = "#{Thread.current[:formatador].indentation}<#{self.class.name}\n"
  Thread.current[:formatador].indent do
    unless self.class.attributes.empty?
      data << "#{Thread.current[:formatador].indentation}"
      data << self.class.attributes.map {|attribute| "#{attribute}=#{send(attribute).inspect}"}.join(",\n#{Thread.current[:formatador].indentation}")
      data << "\n"
    end
    data << "#{Thread.current[:formatador].indentation}["
    unless self.empty?
      data << "\n"
      Thread.current[:formatador].indent do
        data << self.map {|member| member.inspect}.join(",\n")
        data << "\n"
      end
      data << Thread.current[:formatador].indentation
    end
    data << "]\n"
  end
  data << "#{Thread.current[:formatador].indentation}>"
  data
end
load(objects) click to toggle source
# File lib/fog/core/collection.rb, line 100
def load(objects)
  clear
  for object in objects
    self << new(object)
  end
  self
end
model() click to toggle source
# File lib/fog/core/collection.rb, line 108
def model
  self.class.instance_variable_get('@model')
end
new(attributes = {}) click to toggle source
# File lib/fog/core/collection.rb, line 112
def new(attributes = {})
  unless attributes.is_a?(::Hash)
    raise(ArgumentError.new("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 124
def reload
  clear
  lazy_load
  self
end
table(attributes = nil) click to toggle source
# File lib/fog/core/collection.rb, line 130
def table(attributes = nil)
  Formatador.display_table(self.map {|instance| instance.attributes}, attributes)
end
to_json(options = {}) click to toggle source
# File lib/fog/core/collection.rb, line 134
def to_json(options = {})
  Fog::JSON.encode(self.map {|member| member.attributes})
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.