class Schemacop::V2::StringValidator
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
Schemacop::V2::Node::new
# File lib/schemacop/v2/validator/string_validator.rb, line 9 def initialize(options = {}) super(options) validate_options! end
Public Instance Methods
validate(data, collector)
click to toggle source
Calls superclass method
Schemacop::V2::Node#validate
# File lib/schemacop/v2/validator/string_validator.rb, line 15 def validate(data, collector) super if option?(:min) && data.size < option(:min) collector.error "String must be longer (>=) than #{option(:min)} characters." end if option?(:max) && data.size > option(:max) collector.error "String must be shorter (<=) than #{option(:max)} characters." end end
Protected Instance Methods
validate_options!()
click to toggle source
# File lib/schemacop/v2/validator/string_validator.rb, line 28 def validate_options! option_schema = Schema.new :integer, min: 0 if option?(:min) && option_schema.invalid?(option(:min)) fail Exceptions::InvalidSchemaError, 'String option :min must be an integer >= 0.' elsif option?(:max) && option_schema.invalid?(option(:max)) fail Exceptions::InvalidSchemaError, 'String option :max must be an integer >= 0.' end end