Exception: Pray::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(category, message, parse_kind: nil) ⇒ Error

Returns a new instance of Error.



5
6
7
8
9
# File 'lib/pray/error.rb', line 5

def initialize(category, message, parse_kind: nil)
  @category = category
  @parse_kind = parse_kind
  super(message)
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



11
12
13
# File 'lib/pray/error.rb', line 11

def category
  @category
end

Class Method Details

.integrity(message) ⇒ Object



48
# File 'lib/pray/error.rb', line 48

def self.integrity(message) = new(:integrity, message)

.io(error) ⇒ Object



53
# File 'lib/pray/error.rb', line 53

def self.io(error) = new(:io, error.message)

.manifest(message) ⇒ Object



46
# File 'lib/pray/error.rb', line 46

def self.manifest(message) = new(:manifest, message)

.parse(kind, message) ⇒ Object



42
43
44
# File 'lib/pray/error.rb', line 42

def self.parse(kind, message)
  new(:parse, message, parse_kind: kind)
end

.render(message) ⇒ Object



49
# File 'lib/pray/error.rb', line 49

def self.render(message) = new(:render, message)

.resolution(message) ⇒ Object



47
# File 'lib/pray/error.rb', line 47

def self.resolution(message) = new(:resolution, message)

.unsupported(message) ⇒ Object



51
# File 'lib/pray/error.rb', line 51

def self.unsupported(message) = new(:unsupported, message)

.usage(message) ⇒ Object



52
# File 'lib/pray/error.rb', line 52

def self.usage(message) = new(:usage, message)

.verify(message) ⇒ Object



50
# File 'lib/pray/error.rb', line 50

def self.verify(message) = new(:verify, message)

Instance Method Details

#exit_codeObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pray/error.rb', line 13

def exit_code
  case category
  when :parse, :usage then 2
  when :manifest, :io then 1
  when :resolution then 3
  when :integrity then 4
  when :render then 5
  when :verify then 6
  when :unsupported then 8
  else 1
  end
end

#to_sObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pray/error.rb', line 26

def to_s
  prefix = case category
  when :parse then "#{@parse_kind} parse error"
  when :usage then "usage error"
  when :manifest then "manifest error"
  when :resolution then "resolution error"
  when :integrity then "integrity error"
  when :render then "render error"
  when :verify then "verify error"
  when :unsupported then "unsupported feature"
  when :io then "I/O error"
  else category.to_s
  end
  "#{prefix}: #{super}"
end