Class: Fog::Hyperv::Collection
- Inherits:
-
Collection
- Object
- Collection
- Fog::Hyperv::Collection
show all
- Defined in:
- lib/fog/collection.rb
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
|
.requires? ⇒ Boolean
10
11
12
|
# File 'lib/fog/collection.rb', line 10
def self.requires?
@requires ||= []
end
|
Instance Method Details
#all(filters = {}) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/fog/collection.rb', line 21
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
42
43
44
45
46
|
# File 'lib/fog/collection.rb', line 42
def create(attributes = {})
object = new(attributes)
object.save
object
end
|
#get(filters = {}) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/fog/collection.rb', line 29
def get(filters = {})
data = self.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
37
38
39
40
|
# File 'lib/fog/collection.rb', line 37
def new(options = {})
requires(*self.class.requires?)
super(search_attributes.merge(options))
end
|
#search_attributes ⇒ Object
14
15
16
17
18
19
|
# File 'lib/fog/collection.rb', line 14
def search_attributes
attributes.dup.merge(
_return_fields: model.attributes - model.lazy_attributes,
_json_depth: 1
)
end
|