Class: SoberSwag::Reporting::Output::List

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

Overview

Serialize a list of some other output type. Passes views down.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Interface

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

Constructor Details

#initialize(element_output) ⇒ List

Returns a new instance of List.



8
9
10
# File 'lib/sober_swag/reporting/output/list.rb', line 8

def initialize(element_output)
  @element_output = element_output
end

Instance Attribute Details

#element_outputObject (readonly)

Returns the value of attribute element_output.



12
13
14
# File 'lib/sober_swag/reporting/output/list.rb', line 12

def element_output
  @element_output
end

Instance Method Details

#call(input) ⇒ Object



22
23
24
# File 'lib/sober_swag/reporting/output/list.rb', line 22

def call(input)
  input.map { |i| element_output.call(i) }
end

#serialize_report(input) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sober_swag/reporting/output/list.rb', line 37

def serialize_report(input)
  return Report::Value.new(['could not be made an array']) unless input.respond_to?(:map)

  errs = {}
  mapped = input.map.with_index do |item, idx|
    element_output.serialize_report(item).tap { |e| errs[idx] = e if e.is_a?(Report::Base) }
  end

  if errs.any?
    Report::List.new(errs)
  else
    mapped
  end
end

#swagger_schemaObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/sober_swag/reporting/output/list.rb', line 26

def swagger_schema
  schema, found = element_output.swagger_schema
  [
    {
      type: 'array',
      items: schema
    },
    found
  ]
end

#view(view) ⇒ Object



14
15
16
# File 'lib/sober_swag/reporting/output/list.rb', line 14

def view(view)
  List.new(element_output.view(view))
end

#viewsObject



18
19
20
# File 'lib/sober_swag/reporting/output/list.rb', line 18

def views
  element_output.views
end