Class: Jsapi::Meta::Schema::Validation::Minimum
- Defined in:
- lib/jsapi/meta/schema/validation/minimum.rb
Instance Attribute Summary collapse
-
#exclusive ⇒ Object
readonly
Returns the value of attribute exclusive.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(value, exclusive: false) ⇒ Minimum
constructor
A new instance of Minimum.
- #to_json_schema_validation ⇒ Object
- #to_openapi_validation(version) ⇒ Object
- #validate(value, errors) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(value, exclusive: false) ⇒ Minimum
Returns a new instance of Minimum.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jsapi/meta/schema/validation/minimum.rb', line 10 def initialize(value, exclusive: false) if exclusive unless value.respond_to?(:>) raise ArgumentError, "invalid exclusive minimum: #{value.inspect}" end else unless value.respond_to?(:>=) raise ArgumentError, "invalid minimum: #{value.inspect}" end end super(value) @exclusive = exclusive end |
Instance Attribute Details
#exclusive ⇒ Object (readonly)
Returns the value of attribute exclusive.
8 9 10 |
# File 'lib/jsapi/meta/schema/validation/minimum.rb', line 8 def exclusive @exclusive end |
Instance Method Details
#to_json_schema_validation ⇒ Object
38 39 40 41 42 |
# File 'lib/jsapi/meta/schema/validation/minimum.rb', line 38 def to_json_schema_validation return super unless exclusive { exclusiveMinimum: value } end |
#to_openapi_validation(version) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/jsapi/meta/schema/validation/minimum.rb', line 44 def to_openapi_validation(version) version = OpenAPI::Version.from(version) return to_json_schema_validation if version.major == 3 && version.minor == 1 return super unless exclusive { minimum: value, exclusiveMinimum: true } end |
#validate(value, errors) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jsapi/meta/schema/validation/minimum.rb', line 25 def validate(value, errors) if exclusive return true if value > self.value errors.add(:base, :greater_than, count: self.value) else return true if value >= self.value errors.add(:base, :greater_than_or_equal_to, count: self.value) end false end |