class ChefAPI::Validator::Type
Attributes
types[R]
Public Class Methods
new(attribute, type)
click to toggle source
Overload the super method to capture the type attribute in the options hash.
Calls superclass method
ChefAPI::Validator::Base::new
# File lib/chef-api/validators/type.rb, line 9 def initialize(attribute, type) super @types = Array(type) end
Public Instance Methods
validate(resource)
click to toggle source
# File lib/chef-api/validators/type.rb, line 14 def validate(resource) value = resource._attributes[attribute] if value && !types.any? { |type| value.is_a?(type) } short_name = type.to_s.split('::').last resource.errors.add(attribute, "must be a kind of #{short_name}") end end