Class: Churn::LocationMapping
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- Churn::LocationMapping
- Defined in:
- lib/churn/location_mapping.rb
Overview
Given a ruby file, map the klass and methods to a range of line numbers The klass and method to line numbers mappings, are stored in klasses_collection and methods_collection this is based off https://github.com/seattlerb/ruby_parser which seems to have some known line number bugs perhaps look at and move more to the style of line numbers from metric_fu https://github.com/metricfu/metric_fu/blob/master/lib/data_structures/line_numbers.rb NOTE: showing more line number issues with Ruby 2.6
Instance Attribute Summary collapse
-
#klasses_collection ⇒ Object
readonly
Returns the value of attribute klasses_collection.
-
#methods_collection ⇒ Object
readonly
Returns the value of attribute methods_collection.
Instance Method Summary collapse
- #analyze_list(exp) ⇒ Object
- #deep_last_line(exp) ⇒ Object
- #get_info(file) ⇒ Object
-
#initialize ⇒ LocationMapping
constructor
A new instance of LocationMapping.
- #process_class(exp) ⇒ Object
- #process_defn(exp) ⇒ Object
Constructor Details
#initialize ⇒ LocationMapping
Returns a new instance of LocationMapping.
14 15 16 17 18 19 20 21 |
# File 'lib/churn/location_mapping.rb', line 14 def initialize() super @klasses_collection = {} @methods_collection = {} @parser = RubyParser.new self.auto_shift_type = true self.require_empty = false end |
Instance Attribute Details
#klasses_collection ⇒ Object (readonly)
Returns the value of attribute klasses_collection.
12 13 14 |
# File 'lib/churn/location_mapping.rb', line 12 def klasses_collection @klasses_collection end |
#methods_collection ⇒ Object (readonly)
Returns the value of attribute methods_collection.
12 13 14 |
# File 'lib/churn/location_mapping.rb', line 12 def methods_collection @methods_collection end |
Instance Method Details
#analyze_list(exp) ⇒ Object
47 48 49 50 |
# File 'lib/churn/location_mapping.rb', line 47 def analyze_list exp process exp.shift until exp.empty? exp end |
#deep_last_line(exp) ⇒ Object
41 42 43 44 45 |
# File 'lib/churn/location_mapping.rb', line 41 def deep_last_line(exp) lines = [] exp.deep_each{|x| lines << x.line; } lines.max + 1 end |
#get_info(file) ⇒ Object
23 24 25 26 |
# File 'lib/churn/location_mapping.rb', line 23 def get_info(file) ast = @parser.process(File.read(file).chomp, file) process ast end |
#process_class(exp) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/churn/location_mapping.rb', line 28 def process_class(exp) name = exp.shift start_line = exp.line last_line = deep_last_line(exp) name = name if name.is_a?(Symbol) name = name.values.value if name.is_a?(Sexp) #deals with cases like class Test::Unit::TestCase @current_class = name @klasses_collection[name.to_s] = [] unless @klasses_collection.include?(name) @klasses_collection[name.to_s] << (start_line..last_line) analyze_list exp s() end |
#process_defn(exp) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/churn/location_mapping.rb', line 52 def process_defn(exp) name = exp.shift start_line = exp.line last_line = deep_last_line(exp) full_name = "#{@current_class}##{name}" @methods_collection[full_name] = [] unless @methods_collection.include?(full_name) @methods_collection[full_name] << (start_line..last_line) return s(:defn, name, process(exp.shift), process(exp.shift)) end |