class Objecheck::Validator::EachKeyRule
EachKeyRule
validates keys in the target by using each_key
Public Class Methods
new(validator, key_schema)
click to toggle source
# File lib/objecheck/validator/each_key_rule.rb, line 20 def initialize(validator, key_schema) @key_rules = validator.compile_schema(key_schema) end
schema()
click to toggle source
# File lib/objecheck/validator/each_key_rule.rb, line 37 def self.schema [{ type: Hash }] end
Public Instance Methods
validate(target, collector)
click to toggle source
# File lib/objecheck/validator/each_key_rule.rb, line 24 def validate(target, collector) if !target.respond_to?(:each_key) collector.add_error('should respond to `each_key`') return end target.each_key do |key| collector.add_prefix_in(".key(#{key.inspect})") do collector.validate(key, @key_rules) end end end