Sha256: 8d9f47065e9e1e2fbc6391523c73c9c0837d91f6159522a3ca26b8bc436f32e5

Contents?: true

Size: 505 Bytes

Versions: 3

Compression:

Stored size: 505 Bytes

Contents

class OpenAPIParser::SchemaValidator
  class BooleanValidator < Base
    def coerce_and_validate(value, schema)
      value = coerce(value) if @coerce_value

      return validator.validate_error(value, schema) unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
      [value, nil]
    end

    private

    def coerce(value)
      if value == "true" || value == "1"
        return true
      end
      if value == "false" || value == "0"
        return false
      end
      value
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openapi_parser-0.1.5 lib/openapi_parser/schema_validators/boolean_validator.rb
openapi_parser-0.1.4 lib/openapi_parser/schema_validators/boolean_validator.rb
openapi_parser-0.1.3 lib/openapi_parser/schema_validators/boolean_validator.rb