Parent

Class/Module Index [+]

Quicksearch

Deltacloud::HardwareProfile::Property

Attributes

default[R]
first[R]

kind == :range

kind[R]
last[R]

kind == :range

name[R]
value[R]

kind == :fixed

values[R]

kind == :enum

Public Class Methods

new(name, values, opts = {}) click to toggle source
# 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

Public Instance Methods

fixed?() click to toggle source
# File lib/deltacloud/hardware_profile.rb, line 67
def fixed?
  kind == :fixed
end
include?(v) click to toggle source
# File lib/deltacloud/hardware_profile.rb, line 96
def include?(v)
  if kind == :fixed
    return v == value
  else
    return values.include?(v)
  end
end
param() click to toggle source
# File lib/deltacloud/hardware_profile.rb, line 63
def param
  :"hwp_#{name}"
end
to_param() click to toggle source
# File lib/deltacloud/hardware_profile.rb, line 92
def to_param
  Validation::Param.new([param, :string, :optional, []])
end
unit() click to toggle source
# File lib/deltacloud/hardware_profile.rb, line 59
def unit
  HardwareProfile.unit(name)
end
valid?(v) click to toggle source
# 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.