class ChefAPI::Validator::Base

Attributes

attribute[R]

@return [Symbol]

the attribute to apply this validation on
options[R]

@return [Hash]

the hash of additional arguments passed in

Public Class Methods

new(attribute, options = {}) click to toggle source

Create anew validator.

@param [Symbol] attribute

the attribute to apply this validation on

@param [Hash] options

the list of options passed in
# File lib/chef-api/validators/base.rb, line 23
def initialize(attribute, options = {})
  @attribute = attribute
  @options   = options.is_a?(Hash) ? options : {}
end

Public Instance Methods

inspect() click to toggle source

The string representation of this validation.

@return [String]

# File lib/chef-api/validators/base.rb, line 67
def inspect
  "#<#{classname} :#{attribute}>"
end
key() click to toggle source

Just in case someone forgets to define a key, this will return the class's underscored name without “validator” as a symbol.

@example

FooValidator.new.key #=> :foo

@return [Symbol]

# File lib/chef-api/validators/base.rb, line 37
def key
  name = self.class.name.split('::').last
  Util.underscore(name).to_sym
end
to_s() click to toggle source

The string representation of this validation.

@return [String]

# File lib/chef-api/validators/base.rb, line 58
def to_s
  "#<#{classname}>"
end
validate(resource) click to toggle source

Execute the validations. This is an abstract class and must be overridden in custom validators.

@param [Resource::Base::Base] resource

the parent resource to validate against
# File lib/chef-api/validators/base.rb, line 49
def validate(resource)
  raise Error::AbstractMethod.new(method: 'Validators::Base#validate')
end

Private Instance Methods

classname() click to toggle source

The class name for this validator.

@return [String]

# File lib/chef-api/validators/base.rb, line 78
def classname
  @classname ||= self.class.name.split('::')[1..-1].join('::')
end