Class: Rook::CookbookValidator
- Inherits:
-
Kwalify::Validator
- Object
- Kwalify::Validator
- Rook::CookbookValidator
- Defined in:
- lib/rook/cookbook.rb
Constant Summary collapse
- @@schema =
parser.parse()
Instance Method Summary collapse
- #create_error(path, message) ⇒ Object
-
#initialize ⇒ CookbookValidator
constructor
A new instance of CookbookValidator.
- #validate_hook(value, rule, path, errors) ⇒ Object
Constructor Details
#initialize ⇒ CookbookValidator
Returns a new instance of CookbookValidator.
41 42 43 |
# File 'lib/rook/cookbook.rb', line 41 def initialize() super(@@schema) end |
Instance Method Details
#create_error(path, message) ⇒ Object
46 47 48 |
# File 'lib/rook/cookbook.rb', line 46 def create_error(path, ) return Kwalify::ValidationError.new(, path) end |
#validate_hook(value, rule, path, errors) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rook/cookbook.rb', line 55 def validate_hook(value, rule, path, errors) case rule.name when 'MATERIAL' unless value.is_a?(String) || value.is_a?(Symbol) errors << create_error(path, "String or Symbol is required.") end when 'PROPERTY' unless value.key?('value') || value.key?('expr') errors << create_error(path, "either 'value' or 'expr' is required.") end when 'PROP' value.each do |k, v| if !k.is_a?(String) errors << create_error("#{path}/#{k}", "property name is not a string.") elsif k !~ /\A[a-zA-Z_]\w*\*?\z/ && k != '.desc' errors << create_error("#{path}/#{k}", "invlaid property name.") elsif k[-1] == ?* && !v.is_a?(String) errors << create_error("#{path}/#{k}", "expr is not a string.") end end end if rule.name end |