class ViewModel::AbstractErrorCollection

Abstract collection of errors

def self.for_errors(errors)

def self.for_errors(errors)
  if errors.size == 1
    errors.first
  else
    self.new(errors)
  end
end

def aggregation?

def aggregation?
  true
end

def cause_details

def cause_details
  causes.map(&:detail).join('; ')
end

def detail

def detail
  "ViewModel::AbstractErrors: #{cause_details}"
end

def initialize(causes)

def initialize(causes)
  @causes = Array.wrap(causes)
  unless @causes.present?
    raise ArgumentError.new('A collection must have at least one cause')
  end
  super()
end

def status

def status
  causes.inject(causes.first.status) do |status, cause|
    if status == cause.status
      status
    else
      400
    end
  end
end