Exception: ViewModel::AbstractErrorCollection

Inherits:
AbstractError
  • Object
show all
Defined in:
lib/view_model/error.rb

Overview

Abstract collection of errors

Direct Known Subclasses

DeserializationError::Collection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractError

#code, #exception, #meta, #title, #to_s, #view

Constructor Details

#initialize(causes) ⇒ AbstractErrorCollection

Returns a new instance of AbstractErrorCollection.



118
119
120
121
122
123
124
125
# File 'lib/view_model/error.rb', line 118

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

  super()
end

Instance Attribute Details

#causesObject (readonly)

Returns the value of attribute causes.



116
117
118
# File 'lib/view_model/error.rb', line 116

def causes
  @causes
end

Class Method Details

.for_errors(errors) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/view_model/error.rb', line 145

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

Instance Method Details

#aggregation?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/view_model/error.rb', line 141

def aggregation?
  true
end

#detailObject



137
138
139
# File 'lib/view_model/error.rb', line 137

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

#statusObject



127
128
129
130
131
132
133
134
135
# File 'lib/view_model/error.rb', line 127

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