Class: Fog::Proxmox::Collection

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/proxmox/models/collection.rb

Overview

class Collection proxmox

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#responseObject

Returns the value of attribute response


28
29
30
# File 'lib/fog/proxmox/models/collection.rb', line 28

def response
  @response
end

Instance Method Details

#all(_options = {}) ⇒ Object

Returns detailed list of records


55
56
57
# File 'lib/fog/proxmox/models/collection.rb', line 55

def all(_options = {})
  raise Fog::Proxmox::Errors::InterfaceNotImplemented, not_implemented('all')
end

#clear_ignored_attributes(object, attributes_ignored = []) ⇒ Object

clear attributes non persistent


39
40
41
42
# File 'lib/fog/proxmox/models/collection.rb', line 39

def clear_ignored_attributes(object, attributes_ignored = [])
  attributes_ignored.each { |attribute| object.delete_if { |key, _value| key == attribute } }
  object
end

#create(attributes = {}) ⇒ Object

Proxmox object creation requires identity and return null


49
50
51
52
# File 'lib/fog/proxmox/models/collection.rb', line 49

def create(attributes = {})
  object = new(attributes)
  object.create(attributes)
end

#destroy(_uuid) ⇒ Object

Destroys record given record's UUID


76
77
78
# File 'lib/fog/proxmox/models/collection.rb', line 76

def destroy(_uuid)
  raise Fog::Proxmox::Errors::InterfaceNotImplemented, not_implemented('destroy')
end

#find_by_id(uuid) ⇒ Object


71
72
73
# File 'lib/fog/proxmox/models/collection.rb', line 71

def find_by_id(uuid)
  get(uuid)
end

#get(_uuid) ⇒ Object

Gets record given record's UUID


67
68
69
# File 'lib/fog/proxmox/models/collection.rb', line 67

def get(_uuid)
  raise Fog::Proxmox::Errors::InterfaceNotImplemented, not_implemented('get')
end

#load_response(response, _index = nil, attributes_ignored = []) ⇒ Object


30
31
32
33
34
35
36
# File 'lib/fog/proxmox/models/collection.rb', line 30

def load_response(response, _index = nil, attributes_ignored = [])
  body = JSON.decode(response.body)
  objects = body['data']
  clear && objects.each { |object| self << new(clear_ignored_attributes(object, attributes_ignored)) }
  self.response = response
  self
end

#not_implemented(method) ⇒ Object


80
81
82
# File 'lib/fog/proxmox/models/collection.rb', line 80

def not_implemented(method)
  "Method #{method} is not implemented"
end

#read(response, attribute) ⇒ Object


44
45
46
# File 'lib/fog/proxmox/models/collection.rb', line 44

def read(response, attribute)
  response.body[attribute]
end

#summary(options = {}) ⇒ Object

Returns non detailed list of records, usually just subset of attributes, which makes this call more effective. Not all Proxmox services support non detailed list, so it delegates to :all by default.


62
63
64
# File 'lib/fog/proxmox/models/collection.rb', line 62

def summary(options = {})
  all(options)
end