Class: SoberSwag::Reporting::Input::Either
- Defined in:
- lib/sober_swag/reporting/input/either.rb
Overview
Parses either one input, or another. Left-biased.
Instance Attribute Summary collapse
-
#lhs ⇒ Base
readonly
Parser for LHS.
-
#rhs ⇒ Base
readonly
Parser for RHS.
Instance Method Summary collapse
- #call(value) ⇒ Object
- #defs_for(schema) ⇒ Object private
-
#initialize(lhs, rhs) ⇒ Either
constructor
A new instance of Either.
- #swagger_schema ⇒ Object
Methods included from Interface
#add_schema_key, #call!, #described, #enum, #format, #in_range, #list, #mapped, #modify_schema, #multiple_of, #optional, #or, #referenced, #swagger_path_schema, #swagger_query_schema, #|
Constructor Details
#initialize(lhs, rhs) ⇒ Either
Returns a new instance of Either.
11 12 13 14 |
# File 'lib/sober_swag/reporting/input/either.rb', line 11 def initialize(lhs, rhs) @lhs = lhs @rhs = rhs end |
Instance Attribute Details
#lhs ⇒ Base (readonly)
Returns parser for LHS.
18 19 20 |
# File 'lib/sober_swag/reporting/input/either.rb', line 18 def lhs @lhs end |
#rhs ⇒ Base (readonly)
Returns parser for RHS.
21 22 23 |
# File 'lib/sober_swag/reporting/input/either.rb', line 21 def rhs @rhs end |
Instance Method Details
#call(value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sober_swag/reporting/input/either.rb', line 23 def call(value) maybe_lhs = lhs.call(value) return maybe_lhs unless maybe_lhs.is_a?(Report::Base) maybe_rhs = rhs.call(value) return maybe_rhs unless maybe_rhs.is_a?(Report::Base) Report::Either.new(maybe_lhs, maybe_rhs) end |
#defs_for(schema) ⇒ Object (private)
45 46 47 |
# File 'lib/sober_swag/reporting/input/either.rb', line 45 def defs_for(schema) schema[:oneOf] || [schema] end |
#swagger_schema ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/sober_swag/reporting/input/either.rb', line 35 def swagger_schema lhs_val, lhs_set = lhs.swagger_schema rhs_val, rhs_set = rhs.swagger_schema val = { oneOf: defs_for(lhs_val) + defs_for(rhs_val) } [val, lhs_set.merge(rhs_set)] end |