Class: Jsapi::Meta::Schema::Validation::MinLength
- Defined in:
- lib/jsapi/meta/schema/validation/min_length.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(value) ⇒ MinLength
constructor
A new instance of MinLength.
- #validate(value, errors) ⇒ Object
Methods inherited from Base
keyword, #to_json_schema_validation, #to_openapi_validation
Constructor Details
#initialize(value) ⇒ MinLength
Returns a new instance of MinLength.
8 9 10 11 12 13 14 |
# File 'lib/jsapi/meta/schema/validation/min_length.rb', line 8 def initialize(value) unless value.respond_to?(:>=) raise ArgumentError, "invalid min length: #{value.inspect}" end super end |
Instance Method Details
#validate(value, errors) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/jsapi/meta/schema/validation/min_length.rb', line 16 def validate(value, errors) return true if value.to_s.length >= self.value errors.add(:base, :too_short, count: self.value) false end |