class SoberSwag::Reporting::Output::Defer

Defer loading of an output for mutual recursion and/or loading time speed. Probably just do this for mutual recursion though.

Note: this *does not* save you from infinite schema generation. This type must return some sort of {Referenced} type in order to do that!

The common use case for this is mutual recursion. Something like…

“`ruby class PersonOutput < SoberSwag::Reporting::Output::Struct

field :first_name, SoberSwag::Reporting::Output.text
view :detail do
  field :classes, SoberSwag::Reporting::Output::Defer.new { ClassroomOutput.view(:base).array }
end

end

class ClassroomOutut < SoberSwag::Reporting::Output::Struct

field :class_name, SoberSwag::Reporting::Output.text

view :detail do
  field :students, SoberSwag::Reporting::Output::Defer.new { PersonOutput.view(:base).array }
end

end “`

Attributes

other_lazy[R]

Public Class Methods

defer(&block) click to toggle source

Nicer initialization: uses a block.

@yieldreturn [Interface] serializer to use.

# File lib/sober_swag/reporting/output/defer.rb, line 35
def self.defer(&block)
  new(block)
end
new(other_lazy) click to toggle source
# File lib/sober_swag/reporting/output/defer.rb, line 39
def initialize(other_lazy)
  @other_lazy = other_lazy
end

Public Instance Methods

call(input) click to toggle source
# File lib/sober_swag/reporting/output/defer.rb, line 51
def call(input)
  other.call(input)
end
other() click to toggle source

@return [Interface]

# File lib/sober_swag/reporting/output/defer.rb, line 47
def other
  @other ||= other_lazy.call
end
serialize_report(input) click to toggle source
# File lib/sober_swag/reporting/output/defer.rb, line 55
def serialize_report(input)
  other.serialize_report(input)
end
swagger_schema() click to toggle source
# File lib/sober_swag/reporting/output/defer.rb, line 63
def swagger_schema
  other.swagger_schema
end
view(view) click to toggle source
# File lib/sober_swag/reporting/output/defer.rb, line 59
def view(view)
  other.view(view)
end