Exception: Gitgo::Document::InvalidDocumentError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/gitgo/document/invalid_document_error.rb

Overview

Raised by Document#validate for an invalid document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, errors) ⇒ InvalidDocumentError

Returns a new instance of InvalidDocumentError.



8
9
10
11
12
# File 'lib/gitgo/document/invalid_document_error.rb', line 8

def initialize(doc, errors)
  @doc = doc
  @errors = errors
  super format_errors
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



5
6
7
# File 'lib/gitgo/document/invalid_document_error.rb', line 5

def doc
  @doc
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/gitgo/document/invalid_document_error.rb', line 6

def errors
  @errors
end

Instance Method Details

#format_errorsObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/gitgo/document/invalid_document_error.rb', line 14

def format_errors
  lines = []
  errors.keys.sort.each do |key|
    error = errors[key]
    lines << "#{key}: #{error.message} (#{error.class})"
  end
  
  lines.unshift header(lines.length)
  lines.join("\n")
end

#header(n) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/gitgo/document/invalid_document_error.rb', line 25

def header(n)
  case n
  when 0 then "unknown errors"
  when 1 then "found 1 error:"
  else "found #{n} errors:"
  end
end