class SoberSwag::Reporting::Output::ViaMap
Apply a mapping function before calling a base output.
Note that this is applied before the base output. This is different than {SoberSwag::Reporting::Input::Mapped}, which does the reverse. IE, this class does `call block -> pass result to base output`, while the other does `call serializer -> pass result to block`.
If you want to get really nerdy, this is contravariant to `Mapped`.
This lets you do things like making an output that serializes to strings via `to_s`:
“`ruby ToSTextOutput = SoberSwag::Reporting::Output::ViaMap.new
(
SoberSwag::Reporting::Output.text, proc { |arg| arg.to_s }
)
class Person
def to_s 'Person' end
end
ToSTextOutput.call(Person.new) # => 'Person' “`
Attributes
mapper[R]
@return [#call] mapping function
output[R]
@return [Interface] base output
Public Class Methods
new(output, mapper)
click to toggle source
# File lib/sober_swag/reporting/output/via_map.rb, line 32 def initialize(output, mapper) @output = output @mapper = mapper end
Public Instance Methods
call(input)
click to toggle source
# File lib/sober_swag/reporting/output/via_map.rb, line 45 def call(input) output.call(mapper.call(input)) end
serialize_report(input)
click to toggle source
# File lib/sober_swag/reporting/output/via_map.rb, line 49 def serialize_report(input) output.serialize_report(mapper.call(input)) end
swagger_schema()
click to toggle source
# File lib/sober_swag/reporting/output/via_map.rb, line 61 def swagger_schema output.swagger_schema end
view(view)
click to toggle source
# File lib/sober_swag/reporting/output/via_map.rb, line 53 def view(view) ViaMap.new(output.view(view), mapper) end
views()
click to toggle source
# File lib/sober_swag/reporting/output/via_map.rb, line 57 def views output.views end