code_reference_finder 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/code_reference_finder.rb +49 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94060cbeb5c775c09547125432608caf3b8f51b25358cfd33455cb90a4abdaa5
|
4
|
+
data.tar.gz: 3e6d4a10d5d5d25b041b4d7b1c72e5da377c81c1c5cf157b0cea5037f6b11879
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 984ca07965ccf199f4eb2bf29480c084ba5d3e1a4a78faa6f31b3c199736c5861e7099f85f4cf0a268b4a60e33e897fbefb657f5a20a34d666fd8bee317a21d9
|
7
|
+
data.tar.gz: 13696b51bf5b0cf6872913ae0a2e9de03296daac59053dc915772d3da38d3411cc7eb69ba4859265a6c2e7cd3989d560ba31a127736396047ba4579b72f8ebcd
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This is a source code analyzer for finding files containing specific references.
|
2
2
|
|
3
3
|
class CodeReferenceFinder
|
4
|
-
def initialize(dir
|
4
|
+
def initialize(dir: nil, ext: nil, target: nil, ignore: nil)
|
5
5
|
@dir = dir
|
6
6
|
@ext = ext
|
7
7
|
@target = target
|
@@ -10,11 +10,32 @@ class CodeReferenceFinder
|
|
10
10
|
@interesting_paths = nil
|
11
11
|
end
|
12
12
|
|
13
|
-
# Performs a parse and returns
|
14
|
-
def
|
13
|
+
# Performs a parse and returns
|
14
|
+
def get_refs(dir:, ext:, target:, ignore:)
|
15
|
+
@dir = dir
|
16
|
+
@ext = ext
|
17
|
+
@target = target
|
18
|
+
@ignore = ignore
|
19
|
+
@results = nil
|
20
|
+
@interesting_paths = nil
|
21
|
+
|
22
|
+
get_result
|
23
|
+
end
|
24
|
+
|
25
|
+
# Performs a parse and returns result hash.
|
26
|
+
def get_result
|
15
27
|
@interesting_paths = find_interesting_paths()
|
16
|
-
|
17
|
-
|
28
|
+
parse_interesting_paths(@interesting_paths)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the result hash as pretty JSON.
|
32
|
+
def get_pretty_json
|
33
|
+
JSON.pretty_generate(@results)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns the result hash as raw JSON.
|
37
|
+
def get_json
|
38
|
+
JSON.generate(@results)
|
18
39
|
end
|
19
40
|
|
20
41
|
# Returns the result hash, nil if unparsed.
|
@@ -22,6 +43,11 @@ class CodeReferenceFinder
|
|
22
43
|
@results
|
23
44
|
end
|
24
45
|
|
46
|
+
# Returns true if the result hash exists.
|
47
|
+
def has_results?
|
48
|
+
not @results.nil?
|
49
|
+
end
|
50
|
+
|
25
51
|
# Returns the interesting paths array, nil if unparsed.
|
26
52
|
def get_interesting_paths
|
27
53
|
@interesting_paths
|
@@ -79,6 +105,7 @@ class CodeReferenceFinder
|
|
79
105
|
|
80
106
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
81
107
|
|
108
|
+
paths_with_matches = []
|
82
109
|
file_matches = {}
|
83
110
|
refined_target = @target.map {|s| s.split(' ').last}
|
84
111
|
|
@@ -110,8 +137,10 @@ class CodeReferenceFinder
|
|
110
137
|
|
111
138
|
# if there were matches, add them.
|
112
139
|
if line_matches.size > 0
|
140
|
+
path_without_root = path.sub(@dir, '')
|
141
|
+
paths_with_matches << path_without_root
|
113
142
|
file_matches[name] = {
|
114
|
-
:path =>
|
143
|
+
:path => path_without_root,
|
115
144
|
:line_count => i,
|
116
145
|
:ref_count => ref_searches.size,
|
117
146
|
:match_count => line_matches.size,
|
@@ -125,15 +154,21 @@ class CodeReferenceFinder
|
|
125
154
|
|
126
155
|
# Define our results hash and return it as a JSON string.
|
127
156
|
@results = {
|
128
|
-
:
|
129
|
-
:
|
130
|
-
|
131
|
-
|
132
|
-
|
157
|
+
:metadata => {
|
158
|
+
:params => {
|
159
|
+
:dir => @dir,
|
160
|
+
:ext => @ext,
|
161
|
+
:target => @target,
|
162
|
+
:ignore => @ignore
|
163
|
+
},
|
164
|
+
:duration => "#{end_time - start_time} seconds",
|
165
|
+
:paths_with_matches => {
|
166
|
+
:total => paths_with_matches.size,
|
167
|
+
:paths => paths_with_matches
|
168
|
+
}
|
133
169
|
},
|
134
|
-
:
|
135
|
-
:file_matches => file_matches
|
170
|
+
:matches => file_matches
|
136
171
|
}
|
137
|
-
|
172
|
+
@results
|
138
173
|
end
|
139
174
|
end
|