Class: Base::Exceptions::ValidationError
- Inherits:
-
Thrift::Exception
- Object
- Thrift::Exception
- Base::Exceptions::ValidationError
- Defined in:
- lib/upfluence/base/exceptions/validation_error.rb
Class Attribute Summary collapse
-
.domain ⇒ Object
Returns the value of attribute domain.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.domain ⇒ Object
Returns the value of attribute domain.
8 9 10 |
# File 'lib/upfluence/base/exceptions/validation_error.rb', line 8 def domain @domain end |
Class Method Details
.from_model(model) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/upfluence/base/exceptions/validation_error.rb', line 10 def from_model(model) validation_errors = model.errors.details.map do |error_field, errors| errors.map do |error| Base::Exceptions::Validation.new( domain: domain, model: model.model_name.singular, field: error_field.to_s, error: error[:error].to_s ) end end.flatten new(validations: validation_errors) end |
Instance Method Details
#to_json ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/upfluence/base/exceptions/validation_error.rb', line 26 def to_json { errors: validations.reduce([]) do |acc, v| acc << { 'resource' => v.model, 'field' => v.field, 'code' => v.error } end }.to_json end |