Class: Deltacloud::HardwareProfile
- Inherits:
-
Object
- Object
- Deltacloud::HardwareProfile
- Defined in:
- lib/deltacloud/hardware_profile.rb
Defined Under Namespace
Classes: Property
Constant Summary collapse
- UNITS =
{ :memory => "MB", :storage => "GB", :architecture => "label", :cpu => "count" }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #default?(prop, v) ⇒ Boolean
- #each_property(&block) ⇒ Object
- #include?(prop, v) ⇒ Boolean
-
#initialize(name, &block) ⇒ HardwareProfile
constructor
A new instance of HardwareProfile.
- #params ⇒ Object
- #properties ⇒ Object
- #property(name) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ HardwareProfile
Returns a new instance of HardwareProfile.
97 98 99 100 101 |
# File 'lib/deltacloud/hardware_profile.rb', line 97 def initialize(name,&block) @properties = {} @name = name instance_eval &block if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
91 92 93 |
# File 'lib/deltacloud/hardware_profile.rb', line 91 def name @name end |
Class Method Details
.property(prop) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/deltacloud/hardware_profile.rb', line 79 def property(prop) define_method(prop) do |*args| values, opts, *ignored = *args instvar = :"@#{prop}" unless values.nil? @properties[prop] = Property.new(prop, values, opts || {}) end @properties[prop] end end |
.unit(name) ⇒ Object
12 13 14 |
# File 'lib/deltacloud/hardware_profile.rb', line 12 def self.unit(name) UNITS[name] end |
Instance Method Details
#default?(prop, v) ⇒ Boolean
115 116 117 118 |
# File 'lib/deltacloud/hardware_profile.rb', line 115 def default?(prop, v) p = @properties[prop.to_sym] p && p.default.to_s == v end |
#each_property(&block) ⇒ Object
103 104 105 |
# File 'lib/deltacloud/hardware_profile.rb', line 103 def each_property(&block) @properties.each_value { |prop| yield prop } end |
#include?(prop, v) ⇒ Boolean
142 143 144 145 |
# File 'lib/deltacloud/hardware_profile.rb', line 142 def include?(prop, v) p = @properties[prop] p.nil? || p.include?(v) end |
#params ⇒ Object
147 148 149 150 151 |
# File 'lib/deltacloud/hardware_profile.rb', line 147 def params @properties.values.inject([]) { |m, prop| m << prop.to_param }.compact end |
#properties ⇒ Object
107 108 109 |
# File 'lib/deltacloud/hardware_profile.rb', line 107 def properties @properties.values end |
#property(name) ⇒ Object
111 112 113 |
# File 'lib/deltacloud/hardware_profile.rb', line 111 def property(name) @properties[name.to_sym] end |
#to_hash ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/deltacloud/hardware_profile.rb', line 120 def to_hash props = [] self.each_property do |p| if p.kind.eql? :fixed props << { :kind => p.kind, :value => p.value, :name => p.name, :unit => p.unit } else param = { :operation => "create", :method => "post", :name => p.name } if p.kind.eql? :range param[:range] = { :first => p.first, :last => p.last } elsif p.kind.eql? :enum param[:enum] = p.values.collect { |v| { :entry => v } } end param props << { :kind => p.kind, :value => p.default, :name => p.name, :unit => p.unit, :param => param } end end { :id => self.name, :properties => props } end |