Class: Deltacloud::HardwareProfile::Property
- Inherits:
-
Object
- Object
- Deltacloud::HardwareProfile::Property
- Defined in:
- lib/deltacloud/models/hardware_profile.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#first ⇒ Object
readonly
kind == :range.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#last ⇒ Object
readonly
kind == :range.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
readonly
kind == :fixed.
-
#values ⇒ Object
readonly
kind == :enum.
Instance Method Summary collapse
- #fixed? ⇒ Boolean
- #include?(v) ⇒ Boolean
-
#initialize(name, values, opts = {}) ⇒ Property
constructor
A new instance of Property.
- #param ⇒ Object
- #to_param ⇒ Object
- #to_s ⇒ Object
- #unit ⇒ Object
- #valid?(v) ⇒ Boolean
Constructor Details
#initialize(name, values, opts = {}) ⇒ Property
Returns a new instance of Property.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 106 def initialize(name, values, opts = {}) @name = name if values.is_a?(Range) @kind = :range @first = values.first @last = values.last @default = values.first elsif values.is_a?(Array) @kind = :enum @values = values @default = values.first else @kind = :fixed @value = values @default = @value end @default = opts[:default] if opts[:default] end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
98 99 100 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 98 def default @default end |
#first ⇒ Object (readonly)
kind == :range
100 101 102 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 100 def first @first end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
98 99 100 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 98 def kind @kind end |
#last ⇒ Object (readonly)
kind == :range
100 101 102 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 100 def last @last end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
98 99 100 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 98 def name @name end |
#value ⇒ Object (readonly)
kind == :fixed
104 105 106 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 104 def value @value end |
#values ⇒ Object (readonly)
kind == :enum
102 103 104 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 102 def values @values end |
Instance Method Details
#fixed? ⇒ Boolean
137 138 139 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 137 def fixed? kind == :fixed end |
#include?(v) ⇒ Boolean
168 169 170 171 172 173 174 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 168 def include?(v) if kind == :fixed return v == value else return values.include?(v) end end |
#param ⇒ Object
133 134 135 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 133 def param :"hwp_#{name}" end |
#to_param ⇒ Object
162 163 164 165 166 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 162 def to_param if defined? Sinatra::Rabbit Sinatra::Rabbit::Param.new([param, :string, :optional, []]) end end |
#to_s ⇒ Object
125 126 127 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 125 def to_s "#{@default}" end |
#unit ⇒ Object
129 130 131 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 129 def unit HardwareProfile.unit(name) end |
#valid?(v) ⇒ Boolean
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/deltacloud/models/hardware_profile.rb', line 141 def valid?(v) v = convert_property_value_type(v) case kind # NOTE: # Currently we cannot validate fixed values because of UI # limitation. In UI we have multiple hwp_* properties which overide # each other. # Then provider have one 'static' hardware profile and one # 'customizable' when user select the static one the UI also send # values from the customizable one (which will lead to a validation # error because validation algorith will think that client want to # overide fixed values. # # when :fixed then (v == @default.to_s) when :fixed then true when :range then match_type?(first, v) and (first..last).include?(v) when :enum then match_type?(values.first, v) and values.include?(v) else false end end |