Class: ChefAPI::Validator::Base
- Inherits:
-
Object
- Object
- ChefAPI::Validator::Base
- Defined in:
- lib/chef-api/validators/base.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Symbol
readonly
The attribute to apply this validation on.
-
#options ⇒ Hash
readonly
The hash of additional arguments passed in.
Instance Method Summary collapse
-
#initialize(attribute, options = {}) ⇒ Base
constructor
Create anew validator.
-
#inspect ⇒ String
The string representation of this validation.
-
#key ⇒ Symbol
Just in case someone forgets to define a key, this will return the class’s underscored name without “validator” as a symbol.
-
#to_s ⇒ String
The string representation of this validation.
-
#validate(resource) ⇒ Object
Execute the validations.
Constructor Details
#initialize(attribute, options = {}) ⇒ Base
Create anew validator.
23 24 25 26 |
# File 'lib/chef-api/validators/base.rb', line 23 def initialize(attribute, = {}) @attribute = attribute @options = .is_a?(Hash) ? : {} end |
Instance Attribute Details
#attribute ⇒ Symbol (readonly)
Returns the attribute to apply this validation on.
7 8 9 |
# File 'lib/chef-api/validators/base.rb', line 7 def attribute @attribute end |
#options ⇒ Hash (readonly)
Returns the hash of additional arguments passed in.
13 14 15 |
# File 'lib/chef-api/validators/base.rb', line 13 def @options end |
Instance Method Details
#inspect ⇒ String
The string representation of this validation.
67 68 69 |
# File 'lib/chef-api/validators/base.rb', line 67 def inspect "#<#{classname} :#{attribute}>" end |
#key ⇒ Symbol
Just in case someone forgets to define a key, this will return the class’s underscored name without “validator” as a symbol.
37 38 39 40 |
# 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 ⇒ String
The string representation of this validation.
58 59 60 |
# File 'lib/chef-api/validators/base.rb', line 58 def to_s "#<#{classname}>" end |
#validate(resource) ⇒ Object
Execute the validations. This is an abstract class and must be overridden in custom validators.
49 50 51 |
# File 'lib/chef-api/validators/base.rb', line 49 def validate(resource) raise Error::AbstractMethod.new(method: "Validators::Base#validate") end |