# File lib/fog/core/collection.rb, line 37 def self.model(new_model = nil) if new_model.nil? @model else @model = new_model end 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]
# File lib/fog/core/collection.rb, line 66 def initialize(attributes = {}) @service = attributes.delete(:service) @loaded = false merge_attributes(attributes) end
# File lib/fog/core/collection.rb, line 45 def clear @loaded = super end
# File lib/fog/core/collection.rb, line 49 def create(attributes = {}) object = new(attributes) object.save object end
# File lib/fog/core/collection.rb, line 55 def destroy(identity) new(:identity => identity).destroy end
# File lib/fog/core/collection.rb, line 72 def inspect Fog::Formatador.format(self) end
# File lib/fog/core/collection.rb, line 76 def load(objects) clear && objects.each { |object| self << new(object) } self end
# File lib/fog/core/collection.rb, line 81 def model self.class.instance_variable_get("@model") end
# File lib/fog/core/collection.rb, line 85 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
# File lib/fog/core/collection.rb, line 97 def reload clear && lazy_load self end
# File lib/fog/core/collection.rb, line 102 def table(attributes = nil) Fog::Formatador.display_table(map(&:attributes), attributes) end
# File lib/fog/core/collection.rb, line 106 def to_json(_options = {}) Fog::JSON.encode(map(&:attributes)) end
# File lib/fog/core/collection.rb, line 112 def lazy_load all end