lib/rapidoc/yaml_parser.rb in rapidoc-0.0.4 vs lib/rapidoc/yaml_parser.rb in rapidoc-0.0.5
- old
+ new
@@ -10,17 +10,22 @@
#
# @param lines [Array] lines that contain comments
# @param blocks [Hash] lines of blocks, example: { init: 1, end: 4 }
# @return [Hash] resource info
#
- def extract_resource_info( lines, blocks )
+ def extract_resource_info( lines, blocks, file_name )
blocks ? info = [] : blocks = []
blocks.each.map do |b|
if lines[ b[:init] ].include? "=begin resource"
n_lines = b[:end] - b[:init] - 1
- info.push YAML.load( lines[ b[:init] +1, n_lines ].join.gsub(/\ *#/, '') )
+
+ begin
+ info.push YAML.load( lines[ b[:init] +1, n_lines ].join.gsub(/\ *#/, '') )
+ rescue SyntaxError => e
+ puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]"
+ end
end
end
info.first ? info.first : {}
end
@@ -30,17 +35,22 @@
#
# @param lines [Array] lines that contain comments
# @param blocks [Hash] lines of blocks, example: { init: 1, end: 4 }
# @return [Array] all actions info
#
- def extract_actions_info( lines, blocks )
+ def extract_actions_info( lines, blocks, file_name )
info = []
blocks = [] unless blocks
- blocks.each do |block|
- if lines[ block[:init] ].include? "=begin action"
- n_lines = block[:end] - block[:init] - 1
- info << YAML.load( lines[ block[:init] + 1, n_lines ].join.gsub(/\ *#/, '') )
+ blocks.each do |b|
+ if lines[ b[:init] ].include? "=begin action"
+ n_lines = b[:end] - b[:init] - 1
+
+ begin
+ info << YAML.load( lines[ b[:init] + 1, n_lines ].join.gsub(/\ *#/, '') )
+ rescue SyntaxError => e
+ puts "Error parsing block in #{file_name} file [#{b[:init]} - #{b[:end]}]"
+ end
end
end
return info
end