Exception: ViewModel::AbstractErrorCollection
- Inherits:
-
AbstractError
- Object
- StandardError
- AbstractError
- ViewModel::AbstractErrorCollection
- Defined in:
- lib/view_model/error.rb
Overview
Abstract collection of errors
Direct Known Subclasses
Instance Attribute Summary collapse
-
#causes ⇒ Object
readonly
Returns the value of attribute causes.
Class Method Summary collapse
Instance Method Summary collapse
- #aggregation? ⇒ Boolean
- #detail ⇒ Object
-
#initialize(causes) ⇒ AbstractErrorCollection
constructor
A new instance of AbstractErrorCollection.
- #status ⇒ Object
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
#causes ⇒ Object (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
141 142 143 |
# File 'lib/view_model/error.rb', line 141 def aggregation? true end |
#detail ⇒ Object
137 138 139 |
# File 'lib/view_model/error.rb', line 137 def detail "ViewModel::AbstractErrors: #{cause_details}" end |
#status ⇒ Object
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 |