Class: RSpectre::SourceMap

Inherits:
Object
  • Object
show all
Defined in:
lib/rspectre/source_map.rb,
lib/rspectre/source_map/parser.rb

Direct Known Subclasses

Null

Defined Under Namespace

Classes: Null, Parser

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSourceMap

Returns a new instance of SourceMap.



7
8
9
# File 'lib/rspectre/source_map.rb', line 7

def initialize
  super(Hash.new { [] })
end

Class Method Details

.parse(file) ⇒ Object



12
13
14
# File 'lib/rspectre/source_map.rb', line 12

def self.parse(file)
  self::Parser.new(file).populate(new)
end

Instance Method Details

#add(node) ⇒ Object



16
17
18
19
20
# File 'lib/rspectre/source_map.rb', line 16

def add(node)
  return unless node.loc.expression

  map[node.loc.first_line] <<= node
end

#find_method(target_selector, line) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/rspectre/source_map.rb', line 22

def find_method(target_selector, line)
  candidates = find_methods(target_selector, line)

  if candidates.one?
    candidates.first
  else
    warn Color.yellow("Unable to resolve `#{target_selector}` on line #{line}.")
  end
end