Class: Shiplane::ChefErrorParser

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/chef_error_parser.rb

Constant Summary collapse

ERROR_LINE_REGEXP =
/================================================================================/
CHEF_ERRORS =
[
  /ERROR: Exception handlers complete/,
  /FATAL: Chef::Exceptions::ChildConvergeError/,
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ ChefErrorParser

Returns a new instance of ChefErrorParser.


11
12
13
# File 'lib/capistrano/chef_error_parser.rb', line 11

def initialize(error)
  @error = error
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.


9
10
11
# File 'lib/capistrano/chef_error_parser.rb', line 9

def error
  @error
end

Class Method Details

.parse(error) ⇒ Object


31
32
33
# File 'lib/capistrano/chef_error_parser.rb', line 31

def self.parse(error)
  new(error).parse
end

Instance Method Details

#first_lineObject


19
20
21
# File 'lib/capistrano/chef_error_parser.rb', line 19

def first_line
  @first_line ||= lines.index(lines.reverse_each.find{|line| line =~ ERROR_LINE_REGEXP }) || 0
end

#last_lineObject


23
24
25
# File 'lib/capistrano/chef_error_parser.rb', line 23

def last_line
  @last_line ||= lines.index{|line| CHEF_ERRORS.any?{ |error| line =~ error } } || -1
end

#linesObject


15
16
17
# File 'lib/capistrano/chef_error_parser.rb', line 15

def lines
  @lines ||= error.message.split("\n")
end

#parseObject


27
28
29
# File 'lib/capistrano/chef_error_parser.rb', line 27

def parse
  lines[first_line..last_line]
end