Class: CodeReferenceFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/code_reference_finder.rb

Overview

This is a source code analyzer for finding files containing specific references.

Instance Method Summary collapse

Constructor Details

#initialize(dir:, ext:, target:, ignore:) ⇒ CodeReferenceFinder

Returns a new instance of CodeReferenceFinder.



4
5
6
7
8
9
10
11
# File 'lib/code_reference_finder.rb', line 4

def initialize(dir:, ext:, target:, ignore:)
    @dir = dir
    @ext = ext
    @target = target
    @ignore = ignore
    @results = nil
    @interesting_paths = nil
end

Instance Method Details

#get_interesting_pathsObject

Returns the interesting paths array, nil if unparsed.



26
27
28
# File 'lib/code_reference_finder.rb', line 26

def get_interesting_paths
    @interesting_paths
end

#get_jsonObject

Performs a parse and returns JSON results.



14
15
16
17
18
# File 'lib/code_reference_finder.rb', line 14

def get_json
    @interesting_paths = find_interesting_paths()
    json = parse_interesting_paths(@interesting_paths)
    json
end

#get_resultsObject

Returns the result hash, nil if unparsed.



21
22
23
# File 'lib/code_reference_finder.rb', line 21

def get_results
    @results
end

#is_call?(line, ref) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/code_reference_finder.rb', line 65

def is_call?(line, ref)
    line.include? "#{ref}." or line.include? "(#{ref}" or line.include? "#{ref})"
end

#is_comment?(line) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/code_reference_finder.rb', line 61

def is_comment?(line)
    line.start_with? '*' or line.start_with? '/*' or line.start_with? '//'
end

#is_ignorable?(line) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/code_reference_finder.rb', line 76

def is_ignorable?(line)
    @ignore.any? {|s| line.include? s}
end

#is_ref_search_match?(line, refs) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
74
# File 'lib/code_reference_finder.rb', line 69

def is_ref_search_match?(line, refs)
    tokens = line.split(' ')
    matches = []
    refs.each {|ref| matches << ref if tokens.include? ref }
    matches.size > 0
end