lib/base/line_numbers.rb in metric_fu-2.0.1 vs lib/base/line_numbers.rb in metric_fu-2.1.0

- old
+ new

@@ -2,21 +2,24 @@ module MetricFu class LineNumbers def initialize(contents) rp = RubyParser.new - file_sexp = rp.parse(contents) @locations = {} + file_sexp = rp.parse(contents) case file_sexp[0] when :class process_class(file_sexp) when :module process_module(file_sexp) when :block file_sexp.each_of_type(:class) { |sexp| process_class(sexp) } else end + rescue Exception + #catch errors for files ruby_parser fails on + @locations end def in_method? line_number !!@locations.detect do |method_name, line_number_range| line_number_range.include?(line_number) @@ -29,10 +32,15 @@ end return nil unless found_method_and_range found_method_and_range.first end + def start_line_for_method(method) + return nil unless @locations.has_key?(method) + @locations[method].first + end + private def process_module(sexp) module_name = sexp[1] sexp.each_of_type(:class) do |sexp| @@ -61,6 +69,6 @@ sexp.find_and_replace_all(:defn, :ignore_me) sexp.find_and_replace_all(:defs, :ignore_me) end end -end \ No newline at end of file +end