Class: ChefAPI::Validator::Type
- Defined in:
- lib/chef-api/validators/type.rb
Instance Attribute Summary collapse
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(attribute, type) ⇒ Type
constructor
Overload the super method to capture the type attribute in the options hash.
- #validate(resource) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(attribute, type) ⇒ Type
Overload the super method to capture the type attribute in the options hash.
9 10 11 12 |
# File 'lib/chef-api/validators/type.rb', line 9 def initialize(attribute, type) super @types = Array(type) end |
Instance Attribute Details
#types ⇒ Object (readonly)
Returns the value of attribute types.
3 4 5 |
# File 'lib/chef-api/validators/type.rb', line 3 def types @types end |
Instance Method Details
#validate(resource) ⇒ Object
14 15 16 17 18 19 20 21 |
# 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 |