Exception: Respect::Rails::ValidationError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/respect/rails.rb

Direct Known Subclasses

RequestValidationError, ResponseValidationError

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

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 message
  if ::Rails.env.test?
    @context.join("; ")
  else
    @error.message
  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: 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