# File lib/deltacloud/hardware_profile.rb, line 40 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
# File lib/deltacloud/hardware_profile.rb, line 67 def fixed? kind == :fixed end
# File lib/deltacloud/hardware_profile.rb, line 96 def include?(v) if kind == :fixed return v == value else return values.include?(v) end end
# File lib/deltacloud/hardware_profile.rb, line 63 def param :"hwp_#{name}" end
# File lib/deltacloud/hardware_profile.rb, line 92 def to_param Validation::Param.new([param, :string, :optional, []]) end
# File lib/deltacloud/hardware_profile.rb, line 59 def unit HardwareProfile.unit(name) end
# File lib/deltacloud/hardware_profile.rb, line 71 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
Generated with the Darkfish Rdoc Generator 2.