Class: SoberSwag::Reporting::Input::Mapped

Inherits:
Base
  • Object
show all
Defined in:
lib/sober_swag/reporting/input/mapped.rb

Overview

Apply a mapping function over an input.

Instance Attribute Summary collapse

Instance Method Summary collapse

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(input, mapper) ⇒ Mapped

Returns a new instance of Mapped.

Parameters:

  • mapper (#call)

    the mapping function

  • input (Base)

    the base input



10
11
12
13
# File 'lib/sober_swag/reporting/input/mapped.rb', line 10

def initialize(input, mapper)
  @mapper = mapper
  @input = input
end

Instance Attribute Details

#inputBase (readonly)

Returns base input.

Returns:

  • (Base)

    base input



20
21
22
# File 'lib/sober_swag/reporting/input/mapped.rb', line 20

def input
  @input
end

#mapper#call (readonly)

Returns mapping function.

Returns:

  • (#call)

    mapping function



17
18
19
# File 'lib/sober_swag/reporting/input/mapped.rb', line 17

def mapper
  @mapper
end

Instance Method Details

#call(value) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/sober_swag/reporting/input/mapped.rb', line 22

def call(value)
  val = input.call(value)

  return val if val.is_a?(Report::Base)

  mapper.call(val)
end

#swagger_schemaObject



30
31
32
# File 'lib/sober_swag/reporting/input/mapped.rb', line 30

def swagger_schema
  input.swagger_schema
end