Class: SoberSwag::Reporting::Output::Dictionary
- Defined in:
- lib/sober_swag/reporting/output/dictionary.rb
Overview
Output a dictionary of key-value pairs.
Instance Attribute Summary collapse
-
#value_output ⇒ Object
readonly
Returns the value of attribute value_output.
Class Method Summary collapse
Instance Method Summary collapse
- #call(item) ⇒ Object
-
#initialize(value_output) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #serialize_report(item) ⇒ Object
- #swagger_schema ⇒ Object
Methods inherited from Base
Methods included from Interface
#call!, #described, #enum, #in_range, #list, #nilable, #partitioned, #referenced, #reporting?, #serialize, #via_map
Constructor Details
#initialize(value_output) ⇒ Dictionary
Returns a new instance of Dictionary.
11 12 13 |
# File 'lib/sober_swag/reporting/output/dictionary.rb', line 11 def initialize(value_output) @value_output = value_output end |
Instance Attribute Details
#value_output ⇒ Object (readonly)
Returns the value of attribute value_output.
15 16 17 |
# File 'lib/sober_swag/reporting/output/dictionary.rb', line 15 def value_output @value_output end |
Class Method Details
.of(valout) ⇒ Object
7 8 9 |
# File 'lib/sober_swag/reporting/output/dictionary.rb', line 7 def self.of(valout) new(valout) end |
Instance Method Details
#call(item) ⇒ Object
17 18 19 |
# File 'lib/sober_swag/reporting/output/dictionary.rb', line 17 def call(item) item.transform_values { |v| value_output.call(v) } end |
#serialize_report(item) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sober_swag/reporting/output/dictionary.rb', line 21 def serialize_report(item) return Report::Base.new(['was not a dict']) unless item.is_a?(Hash) bad, good = item.map { |k, v| [k, value_output.serialize_report(v)] }.compact.partition { |(_, v)| v.is_a?(Report::Base) } return Report::Object.new(bad.to_h) if bad.any? good.to_h end |
#swagger_schema ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sober_swag/reporting/output/dictionary.rb', line 33 def swagger_schema schema, found = value_output.swagger_schema [ { type: :object, additionalProperties: schema }, found ] end |