Exception: ClassyHash::SchemaViolationError

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

Overview

Raised when a validation fails. Allows ClassyHash#validate_full to continue validation and gather all errors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors = []) ⇒ SchemaViolationError

Initializes a schema violation error with the given list of schema errors.



26
27
28
# File 'lib/classy_hash.rb', line 26

def initialize(errors = [])
  @entries = errors
end

Instance Attribute Details

#entriesObject (readonly)

The list of errors passed to the constructor. Contains an Array of Hashes:

[
  { full_path: ClassyHash.join_path(parent_path, key), message: "something the full_path was supposed to be" },
  ...
]


22
23
24
# File 'lib/classy_hash.rb', line 22

def entries
  @entries
end

Instance Method Details

#to_sObject

Joins all errors passed to the constructor into a comma-separated String.



31
32
33
34
35
36
37
38
39
# File 'lib/classy_hash.rb', line 31

def to_s
  @msg ||= @entries.map{|e|
    begin
      "#{e[:full_path]} is not #{e[:message]}"
    rescue
      "ERR: #{e.inspect}"
    end
  }.join(', ')
end