Class: SoberSwag::Reporting::Output::Defer

Inherits:
Base
  • Object
show all
Defined in:
lib/sober_swag/reporting/output/defer.rb

Overview

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...

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#views

Methods included from Interface

#call!, #described, #enum, #in_range, #list, #nilable, #partitioned, #referenced, #reporting?, #serialize, #via_map

Constructor Details

#initialize(other_lazy) ⇒ Defer

Returns a new instance of Defer.



39
40
41
# File 'lib/sober_swag/reporting/output/defer.rb', line 39

def initialize(other_lazy)
  @other_lazy = other_lazy
end

Instance Attribute Details

#other_lazyObject (readonly)

Returns the value of attribute other_lazy.



43
44
45
# File 'lib/sober_swag/reporting/output/defer.rb', line 43

def other_lazy
  @other_lazy
end

Class Method Details

.defer(&block) ⇒ Object

Nicer initialization: uses a block.

Yield Returns:



35
36
37
# File 'lib/sober_swag/reporting/output/defer.rb', line 35

def self.defer(&block)
  new(block)
end

Instance Method Details

#call(input) ⇒ Object



51
52
53
# File 'lib/sober_swag/reporting/output/defer.rb', line 51

def call(input)
  other.call(input)
end

#otherInterface

Returns:



47
48
49
# File 'lib/sober_swag/reporting/output/defer.rb', line 47

def other
  @other ||= other_lazy.call
end

#serialize_report(input) ⇒ Object



55
56
57
# File 'lib/sober_swag/reporting/output/defer.rb', line 55

def serialize_report(input)
  other.serialize_report(input)
end

#swagger_schemaObject



63
64
65
# File 'lib/sober_swag/reporting/output/defer.rb', line 63

def swagger_schema
  other.swagger_schema
end

#view(view) ⇒ Object



59
60
61
# File 'lib/sober_swag/reporting/output/defer.rb', line 59

def view(view)
  other.view(view)
end