# 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
# 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
# File lib/deltacloud/models/hardware_profile.rb, line 27 def self.unit(name) UNITS[name] end
# File lib/deltacloud/models/hardware_profile.rb, line 71 def default?(prop, v) property(prop) && property(prop).default.to_s == v end
# File lib/deltacloud/models/hardware_profile.rb, line 59 def each_property(&block) @properties.each_value { |prop| yield prop } end
# 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
# File lib/deltacloud/models/hardware_profile.rb, line 83 def params @properties.values.inject([]) { |m, prop| m << prop.to_param }.compact end
# File lib/deltacloud/models/hardware_profile.rb, line 63 def properties @properties.values end
# File lib/deltacloud/models/hardware_profile.rb, line 67 def property(name) @properties[name.to_sym] end
# 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