Class: SoberSwag::Reporting::Output::Object
- Defined in:
- lib/sober_swag/reporting/output/object.rb,
lib/sober_swag/reporting/output/object/property.rb
Overview
Serialize out a JSON object.
Defined Under Namespace
Classes: Property
Instance Attribute Summary collapse
- #properties ⇒ Object readonly
Instance Method Summary collapse
- #call(item) ⇒ Object
-
#initialize(properties) ⇒ Object
constructor
A new instance of Object.
- #serialize_report(item) ⇒ Object
-
#swagger_schema ⇒ Object
rubocop:disable Metrics/MethodLength.
Methods inherited from Base
Methods included from Interface
#call!, #described, #enum, #in_range, #list, #nilable, #partitioned, #referenced, #reporting?, #serialize, #via_map
Constructor Details
#initialize(properties) ⇒ Object
Returns a new instance of Object.
11 12 13 |
# File 'lib/sober_swag/reporting/output/object.rb', line 11 def initialize(properties) @properties = properties end |
Instance Attribute Details
#properties ⇒ Object (readonly)
17 18 19 |
# File 'lib/sober_swag/reporting/output/object.rb', line 17 def properties @properties end |
Instance Method Details
#call(item) ⇒ Object
19 20 21 22 23 |
# File 'lib/sober_swag/reporting/output/object.rb', line 19 def call(item) properties.each.with_object({}) do |(k, v), hash| hash[k] = v.output.call(item) end end |
#serialize_report(item) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/sober_swag/reporting/output/object.rb', line 25 def serialize_report(item) bad, good = properties.map { |k, prop| [k, prop.output.serialize_report(item)] }.partition { |(_, v)| v.is_a?(Report::Base) } return Report::Object.new(bad.to_h) if bad.any? good.to_h end |
#swagger_schema ⇒ Object
rubocop:disable Metrics/MethodLength
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sober_swag/reporting/output/object.rb', line 35 def swagger_schema # rubocop:disable Metrics/MethodLength props, found = properties.each.with_object([{}, {}]) do |(k, v), (field, f)| prop_type, prop_found = v.property_schema field[k] = prop_type f.merge!(prop_found) end [ { type: 'object', properties: props, required: properties.keys }, found ] end |