Sha256: 1521af20b2492d7d8ea1260f6b4d624ec92373bd12c27facf0b9fd6558bad5cc
Contents?: true
Size: 1.11 KB
Versions: 4
Compression:
Stored size: 1.11 KB
Contents
module SoberSwag module Reporting module Input ## # Class to parse an array, where each element has the same type. # # Called List to avoid name conflicts. class List < Base ## # @param element [Base] the parser for elements def initialize(element) @element = element end ## # @return [Base] the parser for elements attr_reader :element def call(value) return Report::Value.new(['was not an array']) unless value.is_a?(Array) # obtain a hash of indexes => errors errs = {} # yes, side effects in a map are evil, but we avoid traversal twice mapped = value.map.with_index do |item, idx| element.call(item).tap { |e| errs[idx] = e if e.is_a?(Report::Base) } end if errs.any? Report::List.new(errs) else mapped end end def swagger_schema schema, found = element.swagger_schema [{ type: 'list', items: schema }, found] end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems