Exception: Garcon::Exceptions::ValidationError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/garcon/exceptions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, type = nil) ⇒ ValidationError

Returns a new instance of ValidationError.



36
37
38
39
40
# File 'lib/garcon/exceptions.rb', line 36

def initialize(value, type = nil)
  @value, @type = value, type
  super(build_message)
  super(detail)
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



34
35
36
# File 'lib/garcon/exceptions.rb', line 34

def type
  @type
end

#valueObject

Returns the value of attribute value.



34
35
36
# File 'lib/garcon/exceptions.rb', line 34

def value
  @value
end

Instance Method Details

#build_messageObject



42
43
44
45
46
47
48
# File 'lib/garcon/exceptions.rb', line 42

def build_message
  if type?
    "#{value} is not a valid #{type}"
  else
    "Failed to validate #{value.inspect}"
  end
end

#detailObject

Pretty string output of exception/error object useful for helpful debug messages.



57
58
59
60
61
62
63
# File 'lib/garcon/exceptions.rb', line 57

def detail
  if backtrace
    %{#{self.class.name}: #{message}\n  #{backtrace.join("\n  ")}\n  LOGGED FROM: #{caller[0]}}
  else
    %{#{self.class.name}: #{message}\n  LOGGED FROM: #{caller[0]}}
  end
end

#type?Boolean

Returns:



50
51
52
# File 'lib/garcon/exceptions.rb', line 50

def type?
  type.nil? ? false : true
end