Exception: Respect::Rails::ValidationError
- Inherits:
-
StandardError
- Object
- StandardError
- Respect::Rails::ValidationError
- Defined in:
- lib/respect/rails.rb
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) context
readonly
Returns the value of attribute context.
-
- (Object) error
readonly
Returns the value of attribute error.
-
- (Object) object
readonly
Returns the value of attribute object.
-
- (Object) part
readonly
Returns the value of attribute part.
Instance Method Summary (collapse)
-
- (ValidationError) initialize(error, part, object)
constructor
A new instance of ValidationError.
- - (Object) message
- - (Object) to_h
- - (Object) to_json
Constructor Details
- (ValidationError) initialize(error, part, object)
A new instance of ValidationError
21 22 23 24 25 26 |
# File 'lib/respect/rails.rb', line 21 def initialize(error, part, object) @error = error @part = ActiveSupport::StringInquirer.new(part.to_s) @object = object @context = error.context + ["in #@part"] end |
Instance Attribute Details
- (Object) context (readonly)
Returns the value of attribute context
30 31 32 |
# File 'lib/respect/rails.rb', line 30 def context @context end |
- (Object) error (readonly)
Returns the value of attribute error
28 29 30 |
# File 'lib/respect/rails.rb', line 28 def error @error end |
- (Object) object (readonly)
Returns the value of attribute object
40 41 42 |
# File 'lib/respect/rails.rb', line 40 def object @object end |
- (Object) part (readonly)
Returns the value of attribute part
29 30 31 |
# File 'lib/respect/rails.rb', line 29 def part @part end |
Instance Method Details
- (Object) message
32 33 34 35 36 37 38 |
# File 'lib/respect/rails.rb', line 32 def if ::Rails.env.test? @context.join("; ") else @error. end end |
- (Object) to_h
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/respect/rails.rb', line 42 def to_h { error: { class: self.class.name, message: , context: context, part: @part, object: @object, } } end |
- (Object) to_json
54 55 56 |
# File 'lib/respect/rails.rb', line 54 def to_json ActiveSupport::JSON.encode(self.to_h) end |