class Fog::Collection
Attributes
Public Class Methods
Source
# File lib/fog/core/collection.rb, line 39 def self.model(new_model = nil) if new_model.nil? @model else @model = new_model end end
Source
# File lib/fog/core/collection.rb, line 68 def initialize(attributes = {}) @service = attributes.delete(:service) @loaded = false merge_attributes(attributes) end
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]
Public Instance Methods
Source
# File lib/fog/core/collection.rb, line 47 def clear @loaded = super end
Calls superclass method
Source
# File lib/fog/core/collection.rb, line 51 def create(attributes = {}) object = new(attributes) object.save object end
Source
# File lib/fog/core/collection.rb, line 57 def destroy(identity) new(identity: identity).destroy end
Source
# File lib/fog/core/collection.rb, line 74 def inspect Fog::Formatador.format(self) end
Source
# File lib/fog/core/collection.rb, line 78 def load(objects) clear && objects.each { |object| self << new(object) } self end
Source
# File lib/fog/core/collection.rb, line 83 def model self.class.instance_variable_get("@model") end
Source
# File lib/fog/core/collection.rb, line 87 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
Source
# File lib/fog/core/collection.rb, line 105 def table(attributes = nil) Fog::Formatador.display_table(map(&:attributes), attributes) end
Source
# File lib/fog/core/collection.rb, line 109 def to_json(_options = {}) Fog::JSON.encode(map(&:attributes)) end