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.
10 11 12 13 14 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 10 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.
6 7 8 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 6 def context @context end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 6 def errors @errors end |
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
6 7 8 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 6 def factory @factory end |
Instance Method Details
#add_error(error, given_context = nil, factory_class = UNDEFINED) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 20 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
31 32 33 34 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 31 def add_errors(errors) errors = errors.to_a if errors.respond_to?(:to_a) errors.each { |e| add_error(e) } end |
#collection ⇒ Object
36 37 38 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 36 def collection ErrorCollection.new(errors) end |
#input ⇒ Object
16 17 18 |
# File 'lib/openapi3_parser/validation/validatable.rb', line 16 def input context.input end |