class Objecheck::Validator::TypeRule
TypeRule
validates type of a target
Public Class Methods
new(_validator, type)
click to toggle source
# File lib/objecheck/validator/type_rule.rb, line 20 def initialize(_validator, type) @type = type end
schema()
click to toggle source
# File lib/objecheck/validator/type_rule.rb, line 32 def self.schema [{ any: [{ type: Module }, { eq: :bool }] }] end
Public Instance Methods
validate(target, collector)
click to toggle source
# File lib/objecheck/validator/type_rule.rb, line 24 def validate(target, collector) if @type == :bool collector.add_error("should be a bool (got #{target.class})") if target != true && target != false elsif !target.is_a?(@type) collector.add_error("should be a #{@type} (got #{target.class})") end end