Class: CodeReferenceFinder
- Inherits:
-
Object
- Object
- CodeReferenceFinder
- Defined in:
- lib/code_reference_finder.rb
Overview
This is a source code analyzer for finding files containing specific references.
Instance Method Summary collapse
-
#get_interesting_paths ⇒ Object
Returns the interesting paths array, nil if unparsed.
-
#get_json ⇒ Object
Returns the result hash as raw JSON.
-
#get_pretty_json ⇒ Object
Returns the result hash as pretty JSON.
-
#get_refs(dir:, ext:, target:, ignore:) ⇒ Object
Performs a parse and returns.
-
#get_result ⇒ Object
Performs a parse and returns result hash.
-
#get_results ⇒ Object
Returns the result hash, nil if unparsed.
-
#has_results? ⇒ Boolean
Returns true if the result hash exists.
-
#initialize(dir: nil, ext: nil, target: nil, ignore: nil) ⇒ CodeReferenceFinder
constructor
A new instance of CodeReferenceFinder.
- #is_call?(line, ref) ⇒ Boolean
- #is_comment?(line) ⇒ Boolean
- #is_ignorable?(line) ⇒ Boolean
- #is_ref_search_match?(line, refs) ⇒ Boolean
Constructor Details
#initialize(dir: nil, ext: nil, target: nil, ignore: nil) ⇒ 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: nil, ext: nil, target: nil, ignore: nil) @dir = dir @ext = ext @target = target @ignore = ignore @results = nil @interesting_paths = nil end |
Instance Method Details
#get_interesting_paths ⇒ Object
Returns the interesting paths array, nil if unparsed.
52 53 54 |
# File 'lib/code_reference_finder.rb', line 52 def get_interesting_paths @interesting_paths end |
#get_json ⇒ Object
Returns the result hash as raw JSON.
37 38 39 |
# File 'lib/code_reference_finder.rb', line 37 def get_json JSON.generate(@results) end |
#get_pretty_json ⇒ Object
Returns the result hash as pretty JSON.
32 33 34 |
# File 'lib/code_reference_finder.rb', line 32 def get_pretty_json JSON.pretty_generate(@results) end |
#get_refs(dir:, ext:, target:, ignore:) ⇒ Object
Performs a parse and returns
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/code_reference_finder.rb', line 14 def get_refs(dir:, ext:, target:, ignore:) @dir = dir @ext = ext @target = target @ignore = ignore @results = nil @interesting_paths = nil get_result end |
#get_result ⇒ Object
Performs a parse and returns result hash.
26 27 28 29 |
# File 'lib/code_reference_finder.rb', line 26 def get_result @interesting_paths = find_interesting_paths() parse_interesting_paths(@interesting_paths) end |
#get_results ⇒ Object
Returns the result hash, nil if unparsed.
42 43 44 |
# File 'lib/code_reference_finder.rb', line 42 def get_results @results end |
#has_results? ⇒ Boolean
Returns true if the result hash exists.
47 48 49 |
# File 'lib/code_reference_finder.rb', line 47 def has_results? not @results.nil? end |
#is_call?(line, ref) ⇒ Boolean
91 92 93 |
# File 'lib/code_reference_finder.rb', line 91 def is_call?(line, ref) line.include? "#{ref}." or line.include? "(#{ref}" or line.include? "#{ref})" end |
#is_comment?(line) ⇒ Boolean
87 88 89 |
# File 'lib/code_reference_finder.rb', line 87 def is_comment?(line) line.start_with? '*' or line.start_with? '/*' or line.start_with? '//' end |
#is_ignorable?(line) ⇒ Boolean
102 103 104 |
# File 'lib/code_reference_finder.rb', line 102 def is_ignorable?(line) @ignore.any? {|s| line.include? s} end |
#is_ref_search_match?(line, refs) ⇒ Boolean
95 96 97 98 99 100 |
# File 'lib/code_reference_finder.rb', line 95 def is_ref_search_match?(line, refs) tokens = line.split(' ') matches = [] refs.each {|ref| matches << ref if tokens.include? ref } matches.size > 0 end |