Class: Deltacloud::HardwareProfile
Defined Under Namespace
Classes: Property
Constant Summary
collapse
- UNITS =
{
:memory => "MB",
:storage => "GB",
:architecture => "label",
:cpu => "count"
}
Instance Attribute Summary collapse
Attributes inherited from BaseModel
#description
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseModel
attr_accessor, attributes, #attributes, #id, #to_entity
Constructor Details
#initialize(profile_id, &block) ⇒ HardwareProfile
Returns a new instance of HardwareProfile.
51
52
53
54
55
56
57
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 51
def initialize(profile_id, &block)
@properties = {}
super(:id => profile_id)
result = instance_eval(&block) if block_given?
@name ||= profile_id
result
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
43
44
45
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 43
def name
@name
end
|
Class Method Details
.property(prop) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 32
def property(prop)
define_method(prop) do |*args|
values, opts, _ = *args
unless values.nil?
@properties[prop] = Property.new(prop, values, opts || {})
end
@properties[prop]
end
end
|
.unit(name) ⇒ Object
27
28
29
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 27
def self.unit(name)
UNITS[name]
end
|
Instance Method Details
#default?(prop, v) ⇒ Boolean
71
72
73
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 71
def default?(prop, v)
property(prop) && property(prop).default.to_s == v
end
|
#each_property(&block) ⇒ Object
59
60
61
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 59
def each_property(&block)
@properties.each_value { |prop| yield prop }
end
|
#include?(prop, v) ⇒ Boolean
75
76
77
78
79
80
81
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 75
def include?(prop, v)
return false unless p = property(prop)
return true if p.kind == :range and (p.first..p.last).include?(v)
return true if p.kind == :enum and p.values.include?(v)
return true if p.kind == :fixed and p.value == v
false
end
|
#params ⇒ Object
83
84
85
86
87
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 83
def params
@properties.values.inject([]) { |m, prop|
m << prop.to_param
}.compact
end
|
#properties ⇒ Object
63
64
65
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 63
def properties
@properties.values
end
|
#property(name) ⇒ Object
67
68
69
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 67
def property(name)
@properties[name.to_sym]
end
|
#to_hash(context) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/deltacloud/models/hardware_profile.rb', line 89
def to_hash(context)
r = {
:id => self.id,
:href => context.hardware_profile_url(self.id),
:name => name,
}
r.merge!({:properties => @properties}) if !@properties.empty?
r
end
|