analyst 0.13.1 → 0.14.0
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/analyst.gemspec +4 -3
- data/lib/analyst/{entity_parser/association.rb → association.rb} +0 -0
- data/lib/analyst/entities/begin.rb +13 -0
- data/lib/analyst/entities/class.rb +97 -0
- data/lib/analyst/entities/empty.rb +10 -0
- data/lib/analyst/entities/entity.rb +67 -0
- data/lib/analyst/entities/method.rb +41 -0
- data/lib/analyst/entities/method_call.rb +28 -0
- data/lib/analyst/entities/module.rb +33 -0
- data/lib/analyst/entities/root.rb +22 -0
- data/lib/analyst/entities/singleton_class.rb +21 -0
- data/lib/analyst/parser.rb +30 -55
- data/lib/analyst/version.rb +1 -1
- data/lib/analyst.rb +40 -9
- data/spec/class_spec.rb +30 -0
- data/spec/fixtures/music.rb +70 -0
- data/spec/method_spec.rb +9 -0
- data/spec/parser_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -0
- metadata +38 -87
- data/lib/analyst/cli.rb +0 -42
- data/lib/analyst/entity_parser/entities/class.rb +0 -92
- data/lib/analyst/entity_parser/entities/empty.rb +0 -13
- data/lib/analyst/entity_parser/entities/entity.rb +0 -29
- data/lib/analyst/entity_parser/entities/method.rb +0 -16
- data/lib/analyst/entity_parser/entities/module.rb +0 -31
- data/lib/analyst/formatters/base.rb +0 -33
- data/lib/analyst/formatters/csv.rb +0 -43
- data/lib/analyst/formatters/html.rb +0 -87
- data/lib/analyst/formatters/html_index.rb +0 -47
- data/lib/analyst/formatters/templates/index.html.haml +0 -92
- data/lib/analyst/formatters/templates/output.html.haml +0 -114
- data/lib/analyst/formatters/text.rb +0 -56
- data/lib/analyst/fukuzatsu/analyzer.rb +0 -162
- data/lib/analyst/fukuzatsu/cli.rb +0 -42
- data/lib/analyst/fukuzatsu/entity_parser/association.rb +0 -24
- data/lib/analyst/fukuzatsu/entity_parser/entities/class.rb +0 -92
- data/lib/analyst/fukuzatsu/entity_parser/entities/empty.rb +0 -13
- data/lib/analyst/fukuzatsu/entity_parser/entities/entity.rb +0 -29
- data/lib/analyst/fukuzatsu/entity_parser/entities/method.rb +0 -16
- data/lib/analyst/fukuzatsu/entity_parser/entities/module.rb +0 -31
- data/lib/analyst/fukuzatsu/formatters/base.rb +0 -33
- data/lib/analyst/fukuzatsu/formatters/csv.rb +0 -43
- data/lib/analyst/fukuzatsu/formatters/html.rb +0 -87
- data/lib/analyst/fukuzatsu/formatters/html_index.rb +0 -47
- data/lib/analyst/fukuzatsu/formatters/templates/index.html.haml +0 -92
- data/lib/analyst/fukuzatsu/formatters/templates/output.html.haml +0 -114
- data/lib/analyst/fukuzatsu/formatters/text.rb +0 -56
- data/lib/analyst/fukuzatsu/line_of_code.rb +0 -19
- data/lib/analyst/fukuzatsu/parsed_file.rb +0 -85
- data/lib/analyst/fukuzatsu/parsed_method.rb +0 -32
- data/lib/analyst/fukuzatsu/parser_original.rb +0 -76
- data/lib/analyst/fukuzatsu/rethink/parser.rb +0 -346
- data/lib/analyst/fukuzatsu/version.rb +0 -3
- data/lib/analyst/line_of_code.rb +0 -19
- data/lib/analyst/parsed_file.rb +0 -85
- data/lib/analyst/parsed_method.rb +0 -32
- data/lib/analyst/rethink/parser.rb +0 -346
- data/spec/analyzer_spec.rb +0 -122
- data/spec/cli_spec.rb +0 -48
- data/spec/fixtures/eg_class.rb +0 -8
- data/spec/fixtures/eg_mod_class.rb +0 -2
- data/spec/fixtures/eg_mod_class_2.rb +0 -5
- data/spec/fixtures/eg_module.rb +0 -2
- data/spec/fixtures/module_with_class.rb +0 -9
- data/spec/fixtures/multiple_methods.rb +0 -7
- data/spec/fixtures/nested_methods.rb +0 -8
- data/spec/fixtures/program_1.rb +0 -19
- data/spec/fixtures/program_2.rb +0 -25
- data/spec/fixtures/program_3.rb +0 -66
- data/spec/fixtures/program_4.rb +0 -1
- data/spec/fixtures/single_class.rb +0 -9
- data/spec/fixtures/single_method.rb +0 -3
- data/spec/formatters/csv_spec.rb +0 -37
- data/spec/formatters/html_index_spec.rb +0 -36
- data/spec/formatters/html_spec.rb +0 -48
- data/spec/formatters/text_spec.rb +0 -39
- data/spec/parsed_file_spec.rb +0 -67
- data/spec/parsed_method_spec.rb +0 -34
data/spec/parser_spec.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Parser" do
|
|
4
|
+
|
|
5
|
+
let(:parser) { Analyst.new("./spec/fixtures/music.rb") }
|
|
6
|
+
|
|
7
|
+
describe "#top_level_classes" do
|
|
8
|
+
|
|
9
|
+
it "lists top-level classes" do
|
|
10
|
+
class_names = parser.top_level_classes.map(&:full_name)
|
|
11
|
+
expect(class_names).to match_array ["Artist", "Singer", "Song"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe "#classes" do
|
|
17
|
+
it "lists all classes from recursive search" do
|
|
18
|
+
all_classes = %w[Artist Singer Song
|
|
19
|
+
Instruments::Stringed Instruments::Guitar
|
|
20
|
+
Performances::Equipment::Amp]
|
|
21
|
+
|
|
22
|
+
class_names = parser.classes.map(&:full_name)
|
|
23
|
+
|
|
24
|
+
expect(class_names).to match_array all_classes
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: analyst
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Coraline Ada Ehmke
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-10-
|
|
12
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: ephemeral
|
|
@@ -17,14 +17,14 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
20
|
+
version: 2.4.0
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
27
|
+
version: 2.4.0
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: poro_plus
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -179,7 +179,21 @@ dependencies:
|
|
|
179
179
|
- - ">="
|
|
180
180
|
- !ruby/object:Gem::Version
|
|
181
181
|
version: '0'
|
|
182
|
-
|
|
182
|
+
- !ruby/object:Gem::Dependency
|
|
183
|
+
name: pry
|
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
|
185
|
+
requirements:
|
|
186
|
+
- - ">="
|
|
187
|
+
- !ruby/object:Gem::Version
|
|
188
|
+
version: '0'
|
|
189
|
+
type: :development
|
|
190
|
+
prerelease: false
|
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
192
|
+
requirements:
|
|
193
|
+
- - ">="
|
|
194
|
+
- !ruby/object:Gem::Version
|
|
195
|
+
version: '0'
|
|
196
|
+
description: A nice API for interacting with parsed Ruby source code.
|
|
183
197
|
email:
|
|
184
198
|
- coraline@idolhands.com
|
|
185
199
|
- mikezx@gmail.com
|
|
@@ -197,68 +211,22 @@ files:
|
|
|
197
211
|
- analyst.gemspec
|
|
198
212
|
- lib/analyst.rb
|
|
199
213
|
- lib/analyst/analyzer.rb
|
|
200
|
-
- lib/analyst/
|
|
201
|
-
- lib/analyst/
|
|
202
|
-
- lib/analyst/
|
|
203
|
-
- lib/analyst/
|
|
204
|
-
- lib/analyst/
|
|
205
|
-
- lib/analyst/
|
|
206
|
-
- lib/analyst/
|
|
207
|
-
- lib/analyst/
|
|
208
|
-
- lib/analyst/
|
|
209
|
-
- lib/analyst/
|
|
210
|
-
- lib/analyst/formatters/html_index.rb
|
|
211
|
-
- lib/analyst/formatters/templates/index.html.haml
|
|
212
|
-
- lib/analyst/formatters/templates/output.html.haml
|
|
213
|
-
- lib/analyst/formatters/text.rb
|
|
214
|
-
- lib/analyst/fukuzatsu/analyzer.rb
|
|
215
|
-
- lib/analyst/fukuzatsu/cli.rb
|
|
216
|
-
- lib/analyst/fukuzatsu/entity_parser/association.rb
|
|
217
|
-
- lib/analyst/fukuzatsu/entity_parser/entities/class.rb
|
|
218
|
-
- lib/analyst/fukuzatsu/entity_parser/entities/empty.rb
|
|
219
|
-
- lib/analyst/fukuzatsu/entity_parser/entities/entity.rb
|
|
220
|
-
- lib/analyst/fukuzatsu/entity_parser/entities/method.rb
|
|
221
|
-
- lib/analyst/fukuzatsu/entity_parser/entities/module.rb
|
|
222
|
-
- lib/analyst/fukuzatsu/formatters/base.rb
|
|
223
|
-
- lib/analyst/fukuzatsu/formatters/csv.rb
|
|
224
|
-
- lib/analyst/fukuzatsu/formatters/html.rb
|
|
225
|
-
- lib/analyst/fukuzatsu/formatters/html_index.rb
|
|
226
|
-
- lib/analyst/fukuzatsu/formatters/templates/index.html.haml
|
|
227
|
-
- lib/analyst/fukuzatsu/formatters/templates/output.html.haml
|
|
228
|
-
- lib/analyst/fukuzatsu/formatters/text.rb
|
|
229
|
-
- lib/analyst/fukuzatsu/line_of_code.rb
|
|
230
|
-
- lib/analyst/fukuzatsu/parsed_file.rb
|
|
231
|
-
- lib/analyst/fukuzatsu/parsed_method.rb
|
|
232
|
-
- lib/analyst/fukuzatsu/parser_original.rb
|
|
233
|
-
- lib/analyst/fukuzatsu/rethink/parser.rb
|
|
234
|
-
- lib/analyst/fukuzatsu/version.rb
|
|
235
|
-
- lib/analyst/line_of_code.rb
|
|
236
|
-
- lib/analyst/parsed_file.rb
|
|
237
|
-
- lib/analyst/parsed_method.rb
|
|
214
|
+
- lib/analyst/association.rb
|
|
215
|
+
- lib/analyst/entities/begin.rb
|
|
216
|
+
- lib/analyst/entities/class.rb
|
|
217
|
+
- lib/analyst/entities/empty.rb
|
|
218
|
+
- lib/analyst/entities/entity.rb
|
|
219
|
+
- lib/analyst/entities/method.rb
|
|
220
|
+
- lib/analyst/entities/method_call.rb
|
|
221
|
+
- lib/analyst/entities/module.rb
|
|
222
|
+
- lib/analyst/entities/root.rb
|
|
223
|
+
- lib/analyst/entities/singleton_class.rb
|
|
238
224
|
- lib/analyst/parser.rb
|
|
239
|
-
- lib/analyst/rethink/parser.rb
|
|
240
225
|
- lib/analyst/version.rb
|
|
241
|
-
- spec/
|
|
242
|
-
- spec/
|
|
243
|
-
- spec/
|
|
244
|
-
- spec/
|
|
245
|
-
- spec/fixtures/eg_mod_class_2.rb
|
|
246
|
-
- spec/fixtures/eg_module.rb
|
|
247
|
-
- spec/fixtures/module_with_class.rb
|
|
248
|
-
- spec/fixtures/multiple_methods.rb
|
|
249
|
-
- spec/fixtures/nested_methods.rb
|
|
250
|
-
- spec/fixtures/program_1.rb
|
|
251
|
-
- spec/fixtures/program_2.rb
|
|
252
|
-
- spec/fixtures/program_3.rb
|
|
253
|
-
- spec/fixtures/program_4.rb
|
|
254
|
-
- spec/fixtures/single_class.rb
|
|
255
|
-
- spec/fixtures/single_method.rb
|
|
256
|
-
- spec/formatters/csv_spec.rb
|
|
257
|
-
- spec/formatters/html_index_spec.rb
|
|
258
|
-
- spec/formatters/html_spec.rb
|
|
259
|
-
- spec/formatters/text_spec.rb
|
|
260
|
-
- spec/parsed_file_spec.rb
|
|
261
|
-
- spec/parsed_method_spec.rb
|
|
226
|
+
- spec/class_spec.rb
|
|
227
|
+
- spec/fixtures/music.rb
|
|
228
|
+
- spec/method_spec.rb
|
|
229
|
+
- spec/parser_spec.rb
|
|
262
230
|
- spec/spec_helper.rb
|
|
263
231
|
homepage: ''
|
|
264
232
|
licenses:
|
|
@@ -283,28 +251,11 @@ rubyforge_project:
|
|
|
283
251
|
rubygems_version: 2.2.2
|
|
284
252
|
signing_key:
|
|
285
253
|
specification_version: 4
|
|
286
|
-
summary:
|
|
254
|
+
summary: A nice API for interacting with parsed Ruby source code.
|
|
287
255
|
test_files:
|
|
288
|
-
- spec/
|
|
289
|
-
- spec/
|
|
290
|
-
- spec/
|
|
291
|
-
- spec/
|
|
292
|
-
- spec/fixtures/eg_mod_class_2.rb
|
|
293
|
-
- spec/fixtures/eg_module.rb
|
|
294
|
-
- spec/fixtures/module_with_class.rb
|
|
295
|
-
- spec/fixtures/multiple_methods.rb
|
|
296
|
-
- spec/fixtures/nested_methods.rb
|
|
297
|
-
- spec/fixtures/program_1.rb
|
|
298
|
-
- spec/fixtures/program_2.rb
|
|
299
|
-
- spec/fixtures/program_3.rb
|
|
300
|
-
- spec/fixtures/program_4.rb
|
|
301
|
-
- spec/fixtures/single_class.rb
|
|
302
|
-
- spec/fixtures/single_method.rb
|
|
303
|
-
- spec/formatters/csv_spec.rb
|
|
304
|
-
- spec/formatters/html_index_spec.rb
|
|
305
|
-
- spec/formatters/html_spec.rb
|
|
306
|
-
- spec/formatters/text_spec.rb
|
|
307
|
-
- spec/parsed_file_spec.rb
|
|
308
|
-
- spec/parsed_method_spec.rb
|
|
256
|
+
- spec/class_spec.rb
|
|
257
|
+
- spec/fixtures/music.rb
|
|
258
|
+
- spec/method_spec.rb
|
|
259
|
+
- spec/parser_spec.rb
|
|
309
260
|
- spec/spec_helper.rb
|
|
310
261
|
has_rdoc:
|
data/lib/analyst/cli.rb
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
require 'thor'
|
|
2
|
-
require 'Analyst'
|
|
3
|
-
|
|
4
|
-
module Analyst
|
|
5
|
-
|
|
6
|
-
class CLI < Thor
|
|
7
|
-
|
|
8
|
-
desc_text = "Formats are text (default, to STDOUT), html, and csv. "
|
|
9
|
-
desc_text << "Example: fuku check foo/ -f html"
|
|
10
|
-
|
|
11
|
-
desc "check PATH_TO_FILE [-f FORMAT] [-t MAX_COMPLEXITY_ALLOWED]", desc_text
|
|
12
|
-
method_option :format, :type => :string, :default => 'text', :aliases => "-f"
|
|
13
|
-
method_option :threshold, :type => :numeric, :default => 0, :aliases => "-t"
|
|
14
|
-
|
|
15
|
-
def check(path="./")
|
|
16
|
-
parser = Analyst::Parser.new(
|
|
17
|
-
path,
|
|
18
|
-
formatter,
|
|
19
|
-
options['threshold']
|
|
20
|
-
)
|
|
21
|
-
parser.parse_files
|
|
22
|
-
parser.report
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
default_task :check
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
def formatter
|
|
30
|
-
case options['format']
|
|
31
|
-
when 'html'
|
|
32
|
-
Formatters::Html
|
|
33
|
-
when 'csv'
|
|
34
|
-
Formatters::Csv
|
|
35
|
-
else
|
|
36
|
-
Formatters::Text
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
#TODO add == to association
|
|
2
|
-
|
|
3
|
-
module Analyst
|
|
4
|
-
|
|
5
|
-
module EntityParser
|
|
6
|
-
module Entities
|
|
7
|
-
class ActiveModel < Entity
|
|
8
|
-
|
|
9
|
-
ASSOCIATIONS = [:belongs_to, :has_one, :has_many, :has_and_belongs_to_many]
|
|
10
|
-
|
|
11
|
-
attr_reader :associations
|
|
12
|
-
|
|
13
|
-
def initialize
|
|
14
|
-
@associations = []
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def handle_send(node)
|
|
18
|
-
target, method_name, *args = node.children
|
|
19
|
-
if ASSOCIATIONS.include?(method_name)
|
|
20
|
-
add_association(method_name, args)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# When a class is reopened, merge its associations
|
|
25
|
-
def merge_associations_from(klass)
|
|
26
|
-
klass.associations.each do |association|
|
|
27
|
-
associations << Association.new(
|
|
28
|
-
type: association.type,
|
|
29
|
-
source: self,
|
|
30
|
-
target_class: association.target_class
|
|
31
|
-
)
|
|
32
|
-
end
|
|
33
|
-
associations.uniq!
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def name
|
|
37
|
-
const_node_array(ast.children.first).join('::')
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def full_name
|
|
41
|
-
parent.full_name.empty? ? name : parent.full_name + '::' + name
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
private
|
|
45
|
-
|
|
46
|
-
def add_association(method_name, args)
|
|
47
|
-
target_class = value_from_hash_node(args.last, :class_name)
|
|
48
|
-
target_class ||= begin
|
|
49
|
-
symbol_node = args.first
|
|
50
|
-
symbol_name = symbol_node.children.first
|
|
51
|
-
symbol_name.pluralize.classify
|
|
52
|
-
end
|
|
53
|
-
association = Association.new(type: method_name, source: self, target_class: target_class)
|
|
54
|
-
associations << association
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
# takes a (const) node and returns an array specifying the fully-qualified
|
|
60
|
-
# constant name that it represents. ya know, so CoolModule::SubMod::SweetClass
|
|
61
|
-
# would be parsed to:
|
|
62
|
-
# (const
|
|
63
|
-
# (const
|
|
64
|
-
# (const nil :CoolModule) :SubMod) :SweetClass)
|
|
65
|
-
# and passing that node here would return [:CoolModule, :SubMod, :SweetClass]
|
|
66
|
-
def const_node_array(node)
|
|
67
|
-
return [] if node.nil?
|
|
68
|
-
raise "expected (const) node or nil, got (#{node.type})" unless node.type == :const
|
|
69
|
-
const_node_array(node.children.first) << node.children[1]
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Fetches value from hash node iff key is symbol and value is str
|
|
73
|
-
# Raises an exception if value is not str
|
|
74
|
-
# Returns nil if key is not found
|
|
75
|
-
def value_from_hash_node(node, key)
|
|
76
|
-
return unless node.type == :hash
|
|
77
|
-
pair = node.children.detect do |pair_node|
|
|
78
|
-
key_symbol_node = pair_node.children.first
|
|
79
|
-
key == key_symbol_node.children.first
|
|
80
|
-
end
|
|
81
|
-
if pair
|
|
82
|
-
value_node = pair.children.last
|
|
83
|
-
throw "Bad type. Expected (str), got (#{value_node.type})" unless value_node.type == :str
|
|
84
|
-
value_node.children.first
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module Analyst
|
|
2
|
-
module EntityParser
|
|
3
|
-
module Entities
|
|
4
|
-
class Entity
|
|
5
|
-
|
|
6
|
-
attr_reader :ast, :parent
|
|
7
|
-
|
|
8
|
-
def initialize(parent, ast)
|
|
9
|
-
@parent = parent
|
|
10
|
-
@ast = ast
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def handle_send_node(node)
|
|
14
|
-
# raise "Subclass must implement handle_send_node"
|
|
15
|
-
# abstract method. btw, this feels wrong -- send should be an entity too. but for now, whatevs.
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def full_name
|
|
19
|
-
throw "Subclass must implement #full_name"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def inspect
|
|
23
|
-
"\#<#{self.class}:#{object_id} full_name=#{full_name}>"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module Analyst
|
|
2
|
-
|
|
3
|
-
module EntityParser
|
|
4
|
-
module Entities
|
|
5
|
-
class Module < Entity
|
|
6
|
-
def name
|
|
7
|
-
const_node_array(ast.children.first).join('::')
|
|
8
|
-
end
|
|
9
|
-
def full_name
|
|
10
|
-
parent.full_name.empty? ? name : parent.full_name + '::' + name
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
# takes a (const) node and returns an array specifying the fully-qualified
|
|
16
|
-
# constant name that it represents. ya know, so CoolModule::SubMod::SweetClass
|
|
17
|
-
# would be parsed to:
|
|
18
|
-
# (const
|
|
19
|
-
# (const
|
|
20
|
-
# (const nil :CoolModule) :SubMod) :SweetClass)
|
|
21
|
-
# and passing that node here would return [:CoolModule, :SubMod, :SweetClass]
|
|
22
|
-
def const_node_array(node)
|
|
23
|
-
return [] if node.nil?
|
|
24
|
-
raise "expected (const) node or nil, got (#{node.type})" unless node.type == :const
|
|
25
|
-
const_node_array(node.children.first) << node.children[1]
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module Formatters
|
|
2
|
-
|
|
3
|
-
module Base
|
|
4
|
-
|
|
5
|
-
def self.included(klass)
|
|
6
|
-
klass.send(:attr_accessor, :file)
|
|
7
|
-
klass.send(:attr_accessor, :source)
|
|
8
|
-
klass.send(:attr_accessor, :output_directory)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def initialize(file, output_directory=nil, source="")
|
|
12
|
-
self.file = file
|
|
13
|
-
self.source = source
|
|
14
|
-
self.output_directory = output_directory
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def filename
|
|
18
|
-
File.basename(self.file.path_to_file) + file_extension
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def output_path
|
|
22
|
-
output_path = File.dirname(File.join(self.output_directory, self.file.path_to_file))
|
|
23
|
-
FileUtils.mkpath(output_path)
|
|
24
|
-
output_path
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def path_to_results
|
|
28
|
-
File.join(output_path, filename)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module Formatters
|
|
2
|
-
|
|
3
|
-
class Csv
|
|
4
|
-
|
|
5
|
-
include Formatters::Base
|
|
6
|
-
|
|
7
|
-
def self.has_index?
|
|
8
|
-
false
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def self.writes_to_file_system?
|
|
12
|
-
true
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def content
|
|
16
|
-
rows + "\r\n"
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def export
|
|
20
|
-
begin
|
|
21
|
-
File.open(path_to_results, 'a') {|outfile| outfile.write(content)}
|
|
22
|
-
rescue Exception => e
|
|
23
|
-
puts "Unable to write output: #{e} #{e.backtrace}"
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def file_extension
|
|
28
|
-
".csv"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def path_to_results
|
|
32
|
-
File.join(output_directory, "results#{file_extension}")
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def rows
|
|
36
|
-
file.methods.map do |method|
|
|
37
|
-
"#{file.path_to_file},#{file.class_name},#{method.name},#{method.complexity}"
|
|
38
|
-
end.join("\r\n")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
end
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
require 'rouge'
|
|
2
|
-
|
|
3
|
-
module Formatters
|
|
4
|
-
|
|
5
|
-
class Html
|
|
6
|
-
|
|
7
|
-
include Formatters::Base
|
|
8
|
-
|
|
9
|
-
def self.has_index?
|
|
10
|
-
true
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.writes_to_file_system?
|
|
14
|
-
true
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.index_class
|
|
18
|
-
Formatters::HtmlIndex
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def columns
|
|
22
|
-
["class", "method", "complexity"]
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def content
|
|
26
|
-
Haml::Engine.new(output_template).render(
|
|
27
|
-
Object.new, {
|
|
28
|
-
header: header,
|
|
29
|
-
rows: rows,
|
|
30
|
-
source_lines: preprocessed,
|
|
31
|
-
class_name: file.class_name,
|
|
32
|
-
complexity: file.complexity,
|
|
33
|
-
path_to_file: file.path_to_file,
|
|
34
|
-
date: Time.now.strftime("%Y/%m/%d"),
|
|
35
|
-
time: Time.now.strftime("%l:%M %P")
|
|
36
|
-
}
|
|
37
|
-
)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def export
|
|
41
|
-
begin
|
|
42
|
-
File.open(path_to_results, 'w') {|outfile| outfile.write(content)}
|
|
43
|
-
rescue Exception => e
|
|
44
|
-
puts "Unable to write output: #{e} #{e.backtrace}"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def formatter
|
|
49
|
-
Rouge::Formatters::HTML.new(line_numbers: true)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def header
|
|
53
|
-
columns.map{|col| "<th>#{col.titleize}</th>"}.join("\r\n")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def lexer
|
|
57
|
-
lexer = Rouge::Lexers::Ruby.new
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def output_template
|
|
61
|
-
File.read(File.dirname(__FILE__) + "/templates/output.html.haml")
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def preprocessed
|
|
65
|
-
formatter.format(lexer.lex(source))
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def rows
|
|
69
|
-
i = 0
|
|
70
|
-
file.methods.inject([]) do |a, method|
|
|
71
|
-
i += 1
|
|
72
|
-
a << "<tr class='#{i % 2 == 1 ? 'even' : 'odd'}'>"
|
|
73
|
-
a << " <td>#{file.class_name}</td>"
|
|
74
|
-
a << " <td>#{method.name}</td>"
|
|
75
|
-
a << " <td>#{method.complexity}</td>"
|
|
76
|
-
a << "</tr>"
|
|
77
|
-
a
|
|
78
|
-
end.join("\r\n")
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def file_extension
|
|
82
|
-
".htm"
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
module Formatters
|
|
2
|
-
|
|
3
|
-
class HtmlIndex
|
|
4
|
-
|
|
5
|
-
include Formatters::Base
|
|
6
|
-
|
|
7
|
-
attr_reader :file_summary, :output_directory
|
|
8
|
-
|
|
9
|
-
def initialize(file_summary, output_directory=nil)
|
|
10
|
-
@file_summary = file_summary
|
|
11
|
-
@output_directory = output_directory
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def content
|
|
15
|
-
Haml::Engine.new(output_template).render(
|
|
16
|
-
Object.new, {
|
|
17
|
-
file_summary: file_summary,
|
|
18
|
-
date: Time.now.strftime("%Y/%m/%d"),
|
|
19
|
-
time: Time.now.strftime("%l:%M %P")
|
|
20
|
-
}
|
|
21
|
-
)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def export
|
|
25
|
-
begin
|
|
26
|
-
File.open(path_to_results, 'w') {|outfile| outfile.write(content)}
|
|
27
|
-
rescue Exception => e
|
|
28
|
-
puts "Unable to write output: #{e} #{e.backtrace}"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def filename
|
|
33
|
-
"index.htm"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def output_path
|
|
37
|
-
FileUtils.mkpath(self.output_directory)
|
|
38
|
-
self.output_directory
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def output_template
|
|
42
|
-
File.read(File.dirname(__FILE__) + "/templates/index.html.haml")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
end
|