attractor 2.0.2 → 2.2.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -6
  3. data/Rakefile +13 -13
  4. data/app/assets/javascripts/index.pack.js +1 -1
  5. data/app/assets/stylesheets/main.css +1 -1
  6. data/exe/attractor +1 -1
  7. data/lib/attractor.rb +13 -13
  8. data/lib/attractor.rb~ +43 -0
  9. data/lib/attractor/#duration_parser.rb# +24 -0
  10. data/lib/attractor/cache.rb +67 -0
  11. data/lib/attractor/{reporters/.keep → cache.rb~} +0 -0
  12. data/lib/attractor/calculators/base_calculator.rb +28 -13
  13. data/lib/attractor/calculators/base_calculator.rb~ +52 -0
  14. data/lib/attractor/cli.rb +33 -44
  15. data/lib/attractor/detectors/base_detector.rb~ +4 -0
  16. data/lib/attractor/duration_parser.rb +4 -4
  17. data/lib/attractor/duration_parser.rb~ +23 -0
  18. data/lib/attractor/gem_names.rb +3 -1
  19. data/lib/attractor/gem_names.rb~ +23 -0
  20. data/lib/attractor/registry_entry.rb +0 -1
  21. data/lib/attractor/registry_entry.rb~ +2 -0
  22. data/lib/attractor/reporters/base_reporter.rb +22 -13
  23. data/lib/attractor/reporters/base_reporter.rb~ +54 -0
  24. data/lib/attractor/reporters/console_reporter.rb +4 -4
  25. data/lib/attractor/reporters/console_reporter.rb~ +21 -0
  26. data/lib/attractor/reporters/html_reporter.rb +23 -25
  27. data/lib/attractor/reporters/html_reporter.rb~ +48 -0
  28. data/lib/attractor/reporters/sinatra_reporter.rb +18 -24
  29. data/lib/attractor/suggester.rb +3 -1
  30. data/lib/attractor/tmp/churn/9f86bc9b7ec6bf59cbf7a111ce8b1159ae128347.json +1 -0
  31. data/lib/attractor/value.rb +8 -4
  32. data/lib/attractor/value.rb~ +30 -0
  33. data/lib/attractor/version.rb +1 -1
  34. data/lib/attractor/watcher.rb +7 -3
  35. data/lib/attractor/watcher.rb~ +24 -0
  36. metadata +29 -31
  37. data/.babelrc +0 -4
  38. data/.eslintrc.json +0 -25
  39. data/.gitignore +0 -20
  40. data/.rubocop.yml +0 -2
  41. data/CHANGELOG.md +0 -95
  42. data/Gemfile +0 -4
  43. data/Guardfile +0 -27
  44. data/attractor.gemspec +0 -65
  45. data/bin/console +0 -14
  46. data/bin/setup +0 -8
  47. data/bin/standardize +0 -4
  48. data/bin/test +0 -6
  49. data/dist/calculator.bundle.js +0 -1
  50. data/package-lock.json +0 -6906
  51. data/package.json +0 -53
  52. data/webpack.config.js +0 -23
@@ -0,0 +1,48 @@
1
+ module Attractor
2
+ # HTML reporter
3
+ class HtmlReporter < BaseReporter
4
+ def report
5
+ super
6
+
7
+ puts 'Generating an HTML report'
8
+ @serve_static = true
9
+
10
+ FileUtils.mkdir_p './attractor_output'
11
+ FileUtils.mkdir_p './attractor_output/stylesheets'
12
+ FileUtils.mkdir_p './attractor_output/images'
13
+ FileUtils.mkdir_p './attractor_output/javascripts'
14
+
15
+ File.open('./attractor_output/images/attractor_logo.svg', 'w') { |file| file.write(logo) }
16
+ File.open('./attractor_output/stylesheets/main.css', 'w') { |file| file.write(css) }
17
+ File.open('./attractor_output/javascripts/index.js', 'w') { |file| file.write(javascript) }
18
+ File.open('./attractor_output/javascripts/index.pack.js', 'w') { |file| file.write(javascript_pack) }
19
+
20
+ File.open('./attractor_output/index.html', 'w') { |file| file.write(render) }
21
+ puts "Generated HTML report at #{File.expand_path './attractor_output/index.html'}"
22
+
23
+ Launchy.open(File.expand_path('./attractor_output/index.html'))
24
+ end
25
+
26
+ def logo
27
+ File.read(File.expand_path('../../../app/assets/images/attractor_logo.svg', __dir__))
28
+ end
29
+
30
+ def css
31
+ File.read(File.expand_path('../../../app/assets/stylesheets/main.css', __dir__))
32
+ end
33
+
34
+ def javascript_pack
35
+ File.read(File.expand_path('../../../app/assets/javascripts/index.pack.js', __dir__))
36
+ end
37
+
38
+ def javascript
39
+ template = Tilt.new(File.expand_path('../../../app/assets/javascripts/index.js.erb', __dir__))
40
+ template.render self
41
+ end
42
+
43
+ def render
44
+ template = Tilt.new(File.expand_path('../../../app/views/index.html.erb', __dir__))
45
+ template.render self
46
+ end
47
+ end
48
+ end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rack/livereload'
4
- require 'rack'
5
- require 'sinatra/base'
3
+ require "rack/livereload"
4
+ require "rack"
5
+ require "sinatra/base"
6
6
 
7
7
  module Attractor
8
8
  # skeleton sinatra app
@@ -13,30 +13,31 @@ module Attractor
13
13
  end
14
14
 
15
15
  enable :static
16
- set :public_folder, File.expand_path('../../../app/assets', __dir__)
16
+ set :public_folder, File.expand_path("../../../app/assets", __dir__)
17
17
  set :show_exceptions, :after_handler
18
18
 
19
- get '/' do
19
+ get "/" do
20
20
  @types = @reporter.types
21
- erb File.read(File.expand_path('../../../app/views/index.html.erb', __dir__))
21
+ erb File.read(File.expand_path("../../../app/views/index.html.erb", __dir__))
22
22
  end
23
23
 
24
- get '/file_prefix' do
25
- { file_prefix: @reporter.file_prefix }.to_json
24
+ get "/file_prefix" do
25
+ {file_prefix: @reporter.file_prefix}.to_json
26
26
  end
27
27
 
28
- get '/values' do
29
- type = params[:type] || 'rb'
28
+ get "/values" do
29
+ type = params[:type] || "rb"
30
30
  @reporter.values(type: type).to_json
31
31
  end
32
32
 
33
- get '/suggestions' do
33
+ get "/suggestions" do
34
34
  threshold = params[:t] || 95
35
- @reporter.suggestions(threshold).to_json
35
+ type = params[:type] || "rb"
36
+ @reporter.suggestions(quantile: threshold, type: type).to_json
36
37
  end
37
38
 
38
39
  error NoMethodError do
39
- { error: env['sinatra.error'].message }.to_json
40
+ {error: env["sinatra.error"].message}.to_json
40
41
  end
41
42
  end
42
43
 
@@ -47,10 +48,10 @@ module Attractor
47
48
 
48
49
  app = AttractorApp.new(self)
49
50
 
50
- puts 'Serving attractor at http://localhost:7890'
51
+ puts "Serving attractor at http://localhost:7890"
51
52
 
52
53
  if @open_browser
53
- Launchy.open('http://localhost:7890') if @open_browser
54
+ Launchy.open("http://localhost:7890") if @open_browser
54
55
  puts "Opening browser window..."
55
56
  end
56
57
 
@@ -62,20 +63,13 @@ module Attractor
62
63
 
63
64
  app = AttractorApp.new(self)
64
65
 
65
- puts 'Serving attractor at http://localhost:7890'
66
+ puts "Serving attractor at http://localhost:7890"
66
67
  if @open_browser
67
- Launchy.open('http://localhost:7890')
68
+ Launchy.open("http://localhost:7890")
68
69
  puts "Opening browser window..."
69
70
  end
70
71
 
71
72
  Rack::Handler::WEBrick.run Rack::LiveReload.new(app), Port: 7890
72
73
  end
73
-
74
- def values(type: 'rb')
75
- @values = @calculators[type].calculate
76
- @values
77
- rescue NoMethodError => e
78
- puts "No calculator for type #{type}"
79
- end
80
74
  end
81
75
  end
@@ -3,6 +3,8 @@
3
3
  module Attractor
4
4
  # makes suggestions for refactorings
5
5
  class Suggester
6
+ attr_accessor :values
7
+
6
8
  def initialize(values)
7
9
  @values = values || []
8
10
  end
@@ -13,7 +15,7 @@ module Attractor
13
15
  quantile = products.percentile(threshold.to_i)
14
16
 
15
17
  @values.select { |val| val.churn * val.complexity > quantile }
16
- .sort_by { |val| val.churn * val.complexity }.reverse
18
+ .sort_by { |val| val.churn * val.complexity }.reverse
17
19
  end
18
20
  end
19
21
  end
@@ -0,0 +1 @@
1
+ {"churn":{"changes":[{"file_path":"app/assets/javascripts/index.pack.js","times_changed":21},{"file_path":"src/javascript/functions.js","times_changed":16},{"file_path":"src/javascript/index.js","times_changed":4}],"class_churn":[],"method_churn":[],"changed_files":[".gitignore","Rakefile","attractor.gemspec","lib/attractor.rb","lib/attractor/calculators/js_calculator.rb","lib/attractor/cli.rb","src/javascript/calculator/index.js","src/javascript/calculator/package-lock.json","src/javascript/calculator/package.json","src/javascript/calculator/webpack.config.js"],"changed_classes":[],"changed_methods":[]}}
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
3
+ require "json"
4
4
 
5
5
  module Attractor
6
6
  # holds a churn/complexity value
7
7
  class Value
8
8
  attr_reader :file_path, :churn, :complexity, :details, :history
9
9
 
10
- def initialize(file_path: '', churn: 1, complexity: 0, details: [], history: [])
10
+ def initialize(file_path: "", churn: 1, complexity: 0, details: [], history: [])
11
11
  @file_path = file_path
12
12
  @churn = churn
13
13
  @complexity = complexity
@@ -15,12 +15,16 @@ module Attractor
15
15
  @history = history
16
16
  end
17
17
 
18
+ def current_commit
19
+ history&.first&.first
20
+ end
21
+
18
22
  def to_s
19
- format('%-64s%8.1f%8i', @file_path, @complexity, @churn)
23
+ format("%-64s%8.1f%8i", @file_path, @complexity, @churn)
20
24
  end
21
25
 
22
26
  def to_h
23
- { file_path: file_path, x: churn, y: complexity, details: details, history: history }
27
+ {file_path: file_path, x: churn, y: complexity, details: details, history: history}
24
28
  end
25
29
 
26
30
  def to_json(_opt)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Attractor
6
+ # holds a churn/complexity value
7
+ class Value
8
+ attr_reader :file_path, :churn, :complexity, :details, :history
9
+
10
+ def initialize(file_path: "", churn: 1, complexity: 0, details: [], history: [])
11
+ @file_path = file_path
12
+ @churn = churn
13
+ @complexity = complexity
14
+ @details = details
15
+ @history = history
16
+ end
17
+
18
+ def to_s
19
+ format("%-64s%8.1f%8i", @file_path, @complexity, @churn)
20
+ end
21
+
22
+ def to_h
23
+ {file_path: file_path, x: churn, y: complexity, details: details, history: history}
24
+ end
25
+
26
+ def to_json(_opt)
27
+ to_h.to_json
28
+ end
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module Attractor
2
- VERSION = "2.0.2"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -1,19 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "listen"
4
+
3
5
  module Attractor
4
6
  # functionality for watching file system changes
5
7
  class Watcher
6
- def initialize(file_prefix, callback)
8
+ def initialize(file_prefix, ignores, callback)
7
9
  @file_prefix = file_prefix
8
10
  @callback = callback
11
+ @ignores = ignores.split(",").map(&:strip)
9
12
  end
10
13
 
11
14
  def watch
12
15
  @callback.call
16
+ ignore = @ignores + [/^attractor_output/]
13
17
 
14
- listener = Listen.to(@file_prefix, ignore: /^attractor_output/) do |modified, _added, _removed|
18
+ listener = Listen.to(File.absolute_path(@file_prefix), ignore: ignore) do |modified, _added, _removed|
15
19
  if modified
16
- puts "#{modified.map(&:to_s).join(', ')} modified, recalculating..."
20
+ puts "#{modified.map(&:to_s).join(", ")} modified, recalculating..."
17
21
  @callback.call
18
22
  end
19
23
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Attractor
4
+ # functionality for watching file system changes
5
+ class Watcher
6
+ def initialize(file_prefix, callback)
7
+ @file_prefix = file_prefix
8
+ @callback = callback
9
+ end
10
+
11
+ def watch
12
+ @callback.call
13
+
14
+ listener = Listen.to(@file_prefix, ignore: /^attractor_output/) do |modified, _added, _removed|
15
+ if modified
16
+ puts "#{modified.map(&:to_s).join(', ')} modified, recalculating..."
17
+ @callback.call
18
+ end
19
+ end
20
+ listener.start
21
+ sleep
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Rubisch
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-05 00:00:00.000000000 Z
11
+ date: 2021-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: churn
@@ -154,30 +154,30 @@ dependencies:
154
154
  name: attractor-javascript
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: 0.2.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: 0.2.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: attractor-ruby
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ">="
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
173
+ version: 0.2.0
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ">="
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: 0.2.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: autoprefixer-rails
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -358,13 +358,6 @@ executables:
358
358
  extensions: []
359
359
  extra_rdoc_files: []
360
360
  files:
361
- - ".babelrc"
362
- - ".eslintrc.json"
363
- - ".gitignore"
364
- - ".rubocop.yml"
365
- - CHANGELOG.md
366
- - Gemfile
367
- - Guardfile
368
361
  - LICENSE
369
362
  - README.md
370
363
  - Rakefile
@@ -376,32 +369,37 @@ files:
376
369
  - app/assets/javascripts/index.pack.js
377
370
  - app/assets/stylesheets/main.css
378
371
  - app/views/index.html.erb
379
- - attractor.gemspec
380
- - bin/console
381
- - bin/setup
382
- - bin/standardize
383
- - bin/test
384
- - dist/calculator.bundle.js
385
372
  - exe/attractor
386
373
  - lib/attractor.rb
374
+ - lib/attractor.rb~
375
+ - lib/attractor/#duration_parser.rb#
376
+ - lib/attractor/cache.rb
377
+ - lib/attractor/cache.rb~
387
378
  - lib/attractor/calculators/base_calculator.rb
379
+ - lib/attractor/calculators/base_calculator.rb~
388
380
  - lib/attractor/cli.rb
389
381
  - lib/attractor/detectors/base_detector.rb
382
+ - lib/attractor/detectors/base_detector.rb~
390
383
  - lib/attractor/duration_parser.rb
384
+ - lib/attractor/duration_parser.rb~
391
385
  - lib/attractor/gem_names.rb
386
+ - lib/attractor/gem_names.rb~
392
387
  - lib/attractor/registry_entry.rb
393
- - lib/attractor/reporters/.keep
388
+ - lib/attractor/registry_entry.rb~
394
389
  - lib/attractor/reporters/base_reporter.rb
390
+ - lib/attractor/reporters/base_reporter.rb~
395
391
  - lib/attractor/reporters/console_reporter.rb
392
+ - lib/attractor/reporters/console_reporter.rb~
396
393
  - lib/attractor/reporters/html_reporter.rb
394
+ - lib/attractor/reporters/html_reporter.rb~
397
395
  - lib/attractor/reporters/sinatra_reporter.rb
398
396
  - lib/attractor/suggester.rb
397
+ - lib/attractor/tmp/churn/9f86bc9b7ec6bf59cbf7a111ce8b1159ae128347.json
399
398
  - lib/attractor/value.rb
399
+ - lib/attractor/value.rb~
400
400
  - lib/attractor/version.rb
401
401
  - lib/attractor/watcher.rb
402
- - package-lock.json
403
- - package.json
404
- - webpack.config.js
402
+ - lib/attractor/watcher.rb~
405
403
  homepage: https://github.com/julianrubisch/attractor
406
404
  licenses:
407
405
  - MIT
@@ -410,7 +408,7 @@ metadata:
410
408
  source_code_uri: https://github.com/julianrubisch/attractor
411
409
  bug_tracker_uri: https://github.com/julianrubisch/attractor/issues
412
410
  changelog_uri: https://github.com/julianrubisch/attractor/CHANGELOG.md
413
- post_install_message:
411
+ post_install_message:
414
412
  rdoc_options: []
415
413
  require_paths:
416
414
  - lib
@@ -425,8 +423,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
423
  - !ruby/object:Gem::Version
426
424
  version: '0'
427
425
  requirements: []
428
- rubygems_version: 3.1.2
429
- signing_key:
426
+ rubygems_version: 3.2.3
427
+ signing_key:
430
428
  specification_version: 4
431
429
  summary: Churn vs Complexity Chart Generator
432
430
  test_files: []
data/.babelrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env", "@babel/preset-react"],
3
- "plugins": ["@babel/plugin-transform-runtime"]
4
- }
data/.eslintrc.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "rules": {},
3
- "env": {
4
- "es6": true,
5
- "browser": true
6
- },
7
- "parserOptions": {
8
- "ecmaVersion": 2018,
9
- "sourceType": "module",
10
- "ecmaFeatures": {
11
- "jsx": true
12
- }
13
- },
14
- "extends": [
15
- "eslint:recommended",
16
- "plugin:prettier/recommended"
17
- ],
18
- "globals": {
19
- "Atomics": "readonly",
20
- "SharedArrayBuffer": "readonly"
21
- },
22
- "plugins": [
23
- "react"
24
- ]
25
- }