Class: Openapi3Parser::Validation::Validatable
- Inherits:
-
Object
- Object
- Openapi3Parser::Validation::Validatable
- Defined in:
- lib/openapi3_parser/validation/validatable.rb
Constant Summary collapse
- UNDEFINED =
Class.new
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
Instance Method Summary collapse
- #add_error(error, given_context = nil, factory_class = UNDEFINED) ⇒ Object
- #add_errors(errors) ⇒ Object
- #collection ⇒ Object
-
#initialize(factory, context: nil) ⇒ Validatable
constructor
A new instance of Validatable.
- #input ⇒ Object
Constructor Details
#initialize(factory, context: nil) ⇒ Validatable
Returns a new instance of Validatable.
13 14 15 16 17 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 13 def initialize(factory, context: nil) @factory = factory @context = context || factory.context @errors = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 9 def context @context end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 9 def errors @errors end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
9 10 11 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 9 def factory @factory end |
Instance Method Details
#add_error(error, given_context = nil, factory_class = UNDEFINED) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 23 def add_error(error, given_context = nil, factory_class = UNDEFINED) return unless error return @errors << error if error.is_a?(Validation::Error) @errors << Validation::Error.new( error, given_context || context, factory_class == UNDEFINED ? factory.class : factory_class ) end |
#add_errors(errors) ⇒ Object
34 35 36 37 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 34 def add_errors(errors) errors = errors.to_a if errors.respond_to?(:to_a) errors.each { |e| add_error(e) } end |
#collection ⇒ Object
39 40 41 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 39 def collection ErrorCollection.new(errors) end |
#input ⇒ Object
19 20 21 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 19 def input context.input end |