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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/code_reference_finder.rb +49 -14
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc7980673fd9971d4adb1142c88b3fcbd65564acd7b9714b4136c96db1f1929d
4
- data.tar.gz: d2f1f0c3cefa0cbfcc847dd970c44f00d81fe47ada8177be2b309cb21844311b
3
+ metadata.gz: 94060cbeb5c775c09547125432608caf3b8f51b25358cfd33455cb90a4abdaa5
4
+ data.tar.gz: 3e6d4a10d5d5d25b041b4d7b1c72e5da377c81c1c5cf157b0cea5037f6b11879
5
5
  SHA512:
6
- metadata.gz: 858eb6f09fdd6ca59b47ff5e9a4db9ce23f8b09128e2f99e79dfc68e03c4ed747abd4b2b72fd3f94c425026cb65687a72b12be7fef58d951bc93a443c27258d5
7
- data.tar.gz: a50bf5812e3961e8b94daeb4c2b28c010c290c854727e9e944c054f10dfd08bbb001cf1db2f7fc8b3e4b5a3179b5ca281da977d2b22a04de4d0d34bfa47cc343
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:, ext:, target:, ignore:)
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 JSON results.
14
- def get_json
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
- json = parse_interesting_paths(@interesting_paths)
17
- json
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 => 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
- :params => {
129
- :dir => @dir,
130
- :ext => @ext,
131
- :target => @target,
132
- :ignore => @ignore
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
- :duration => "#{end_time - start_time} seconds",
135
- :file_matches => file_matches
170
+ :matches => file_matches
136
171
  }
137
- JSON.pretty_generate(@results)
172
+ @results
138
173
  end
139
174
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_reference_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Stauffer