class SoberSwag::Reporting::Input::Dictionary

Dictionary types: string keys, something else as a value.

Attributes

value_input[R]

Public Class Methods

new(value_input) click to toggle source
# File lib/sober_swag/reporting/input/dictionary.rb, line 11
def initialize(value_input)
  @value_input = value_input
end
of(input_type) click to toggle source
# File lib/sober_swag/reporting/input/dictionary.rb, line 7
def self.of(input_type)
  new(input_type)
end

Public Instance Methods

call(value) click to toggle source
# File lib/sober_swag/reporting/input/dictionary.rb, line 17
def call(value)
  return Report::Base.new(['was not an object']) unless value.is_a?(Hash)

  bad, good = value.map { |k, v|
    [k, value_input.call(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() click to toggle source
# File lib/sober_swag/reporting/input/dictionary.rb, line 29
def swagger_schema
  schema, found = value_input.swagger_schema

  [{ type: :object, additionalProperties: schema }, found]
end