Class: Fog::Hyperv::Collection

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

Direct Known Subclasses

Compute::Hyperv::Hosts, ComputerCollection

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_method(method = nil) ⇒ Object



6
7
8
# File 'lib/fog/collection.rb', line 6

def self.get_method(method = nil)
  @get_method ||= method
end

.requiresObject



10
11
12
# File 'lib/fog/collection.rb', line 10

def self.requires
  @requires ||= []
end

.requires?(req) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/fog/collection.rb', line 14

def self.requires?(req)
  requires.include? req
end

Instance Method Details

#all(filters = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/fog/collection.rb', line 18

def all(filters = {})
  requires(*self.class.requires)
  data = service.send(method, search_attributes.merge(filters))
  data = [] unless data

  load [data].flatten
end

#create(attributes = {}) ⇒ Object



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

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

#get(filters = {}) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/fog/collection.rb', line 26

def get(filters = {})
  data = all(filters).first
  data if data
rescue Fog::Hyperv::Errors::PSError => err
  raise Fog::Errors::NotFound, err if err.message =~ /Hyper-V was unable to find|^No .* is found/
  raise err
end

#new(options = {}) ⇒ Object



34
35
36
37
# File 'lib/fog/collection.rb', line 34

def new(options = {})
  requires(*self.class.requires)
  super(creation_attributes.merge(options))
end