Class: Churn::LocationMapping

Inherits:
SexpProcessor
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLocationMapping

Returns a new instance of LocationMapping.



10
11
12
13
14
15
16
# File 'lib/churn/location_mapping.rb', line 10

def initialize()
  super
  @klasses_collection  = {}
  @methods_collection  = {}
  @parser              = RubyParser.new
  self.auto_shift_type = true
end

Instance Attribute Details

#klasses_collectionObject (readonly)

Returns the value of attribute klasses_collection.



8
9
10
# File 'lib/churn/location_mapping.rb', line 8

def klasses_collection
  @klasses_collection
end

#methods_collectionObject (readonly)

Returns the value of attribute methods_collection.



8
9
10
# File 'lib/churn/location_mapping.rb', line 8

def methods_collection
  @methods_collection
end

Instance Method Details

#analyze_list(exp) ⇒ Object



36
37
38
# File 'lib/churn/location_mapping.rb', line 36

def analyze_list exp
  process exp.shift until exp.empty?
end

#get_info(file) ⇒ Object



18
19
20
21
# File 'lib/churn/location_mapping.rb', line 18

def get_info(file)
  ast = @parser.process(File.read(file), file)
  process ast
end

#process_class(exp) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/churn/location_mapping.rb', line 23

def process_class(exp)
  name           = exp.shift
  start_line     = exp.line
  last_line      = exp.last.line
  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



40
41
42
43
44
45
46
47
48
# File 'lib/churn/location_mapping.rb', line 40

def process_defn(exp)
  name        = exp.shift
  start_line  = exp.line
  last_line   = exp.last.line
  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