attractor 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +75 -0
- data/Rakefile +0 -3
- data/app/assets/images/attractor_favicon.png +0 -0
- data/app/assets/javascripts/index.js.erb +4 -5
- data/app/assets/javascripts/index.pack.js +6 -6
- data/app/views/index.html.erb +6 -56
- data/attractor.gemspec +7 -1
- data/lib/attractor.rb +29 -14
- data/lib/attractor/calculators/base_calculator.rb +5 -2
- data/lib/attractor/cli.rb +38 -22
- data/lib/attractor/detectors/base_detector.rb +7 -0
- data/lib/attractor/duration_parser.rb +27 -0
- data/lib/attractor/gem_names.rb +16 -0
- data/lib/attractor/registry_entry.rb +12 -0
- data/lib/attractor/reporters/base_reporter.rb +4 -1
- data/lib/attractor/reporters/console_reporter.rb +12 -5
- data/lib/attractor/reporters/html_reporter.rb +31 -4
- data/lib/attractor/reporters/sinatra_reporter.rb +12 -2
- data/lib/attractor/suggester.rb +1 -1
- data/lib/attractor/version.rb +1 -1
- metadata +49 -7
- data/.github/workflows/ruby.yml +0 -25
- data/.rspec +0 -3
- data/.travis.yml +0 -10
- data/lib/attractor/calculators/js_calculator.rb +0 -17
- data/lib/attractor/calculators/ruby_calculator.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 699413053fc8137c150694aa57bc7f4b4ed4c51c2f65d7e3af4549d15d33d274
|
4
|
+
data.tar.gz: f630cd630d43770d34fd1afbffbb717deef4c76942f38917bdf811d8082f33f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d52ffc4e2b05bcc970cc6f9555baeebbee6dc9dde9de83cb0ce15a0a9e8359a5f7d204d3afe5001110d9936c988f0349703fca5d666577be38c3473e3e6cef2
|
7
|
+
data.tar.gz: '088f7c37f1e2769f15c439a295b3e2bb12ee6c1c1b6c2e2ee34dd8920d3a65e9a994509a23adb50c12da5fbb07ec07f94afd5b2d34dc2e6b7709ba65ee746e5b'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## RELEASE 2.0.0
|
2
|
+
|
3
|
+
* BREAKING: Move to a plug-in architecture, see README
|
4
|
+
|
5
|
+
## RELEASE 1.2.0
|
6
|
+
|
7
|
+
* FEATURE: Backport React to static output
|
8
|
+
|
9
|
+
## RELEASE 1.1.1
|
10
|
+
|
11
|
+
* ENHANCEMENT: `--minimum_churn` and `--start_ago` CLI options
|
12
|
+
|
13
|
+
## RELEASE 1.1.0
|
14
|
+
|
15
|
+
* FEATURE: Auto-detect ruby and js projects
|
16
|
+
|
17
|
+
## RELEASE 1.0.2
|
18
|
+
|
19
|
+
* ENHANCEMENT: make launching of browser optional
|
20
|
+
|
1
21
|
## RELEASE 1.0.1
|
2
22
|
|
3
23
|
* FIX: fix sinatra reporter
|
data/README.md
CHANGED
@@ -1,9 +1,28 @@
|
|
1
1
|
# Attractor ![build status](https://travis-ci.org/julianrubisch/attractor.svg?branch=master) <img src="https://user-images.githubusercontent.com/4352208/65411858-3dc84200-ddee-11e9-99b6-c9cdbeb533c5.png" width="32">
|
2
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
3
|
+
[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)
|
4
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
2
5
|
|
3
6
|
![attractor_v0 6 1](https://user-images.githubusercontent.com/4352208/67033292-b41e4280-f115-11e9-8c91-81b3bea4451c.gif)
|
4
7
|
|
5
8
|
Many authors ([Michael Feathers](https://www.agileconnection.com/article/getting-empirical-about-refactoring), [Sandi Metz](https://www.sandimetz.com/blog/2017/9/13/breaking-up-the-behemoth)) have shown that an evaluation of churn vs complexity of files in software projects provide a valuable metric towards code quality. This is another take on the matter, for ruby code, using the `churn` and `flog` projects.
|
6
9
|
|
10
|
+
Here's an [article on medium](https://medium.com/better-programming/why-i-made-my-own-code-quality-tool-c44b40ceaafd) explaining the approach in greater detail.
|
11
|
+
|
12
|
+
## Table of Contents
|
13
|
+
|
14
|
+
* [Installation](#installation)
|
15
|
+
* [Usage](#usage)
|
16
|
+
+ [Live Reloading](#live-reloading)
|
17
|
+
* [CI Usage](#ci-usage)
|
18
|
+
+ [Github Action](#github-action)
|
19
|
+
+ [Gitlab Example](#gitlab-example)
|
20
|
+
* [CLI Commands and Options](#cli-commands-and-options)
|
21
|
+
* [Development](#development)
|
22
|
+
* [Contributing](#contributing)
|
23
|
+
* [Social](#social)
|
24
|
+
* [Logo Attribution](#logo-attribution)
|
25
|
+
|
7
26
|
## Installation
|
8
27
|
|
9
28
|
Add this line to your application's Gemfile:
|
@@ -54,6 +73,33 @@ Enable rack-livereload:
|
|
54
73
|
|
55
74
|
If you have `guard-livereload` (or a similar service) running on your project, you can leverage the hot reloading functionality by specifying `--watch|-w`. Attractor will then live-reload the browser window when a file watched by `guard-livereload` changes.
|
56
75
|
|
76
|
+
## CI Usage
|
77
|
+
|
78
|
+
To use this CLI in a CI environment, use the `--ci` option, which will suppress automatic opening of a browser window.
|
79
|
+
|
80
|
+
### Github Action
|
81
|
+
|
82
|
+
There is a dedicated [Github Action](https://github.com/julianrubisch/attractor-action) that will compile Attractor's output. Here's the action on the [Marketplace](https://github.com/marketplace/actions/attractor-action).
|
83
|
+
|
84
|
+
### Gitlab Example
|
85
|
+
|
86
|
+
The simplest use case is to store the `attractor_output` directory as an artifact.
|
87
|
+
|
88
|
+
```yml
|
89
|
+
attractor:
|
90
|
+
stage: your-stage-label
|
91
|
+
image: ruby:latest
|
92
|
+
script:
|
93
|
+
- gem install attractor
|
94
|
+
- attractor report --ci
|
95
|
+
artifacts:
|
96
|
+
when: on_success
|
97
|
+
paths:
|
98
|
+
- attractor_output
|
99
|
+
```
|
100
|
+
|
101
|
+
Alternatively,
|
102
|
+
|
57
103
|
## CLI Commands and Options
|
58
104
|
|
59
105
|
Print a simple output to console:
|
@@ -62,6 +108,8 @@ Print a simple output to console:
|
|
62
108
|
$ --file_prefix|-p app/models
|
63
109
|
$ --type|-t rb|js
|
64
110
|
$ --watch|-w
|
111
|
+
$ --start_ago|-s (e.g. 5y, 3m, 7w)
|
112
|
+
$ --minimum_churn|-c (minimum times a file must have changed to be processed)
|
65
113
|
|
66
114
|
Generate a full report
|
67
115
|
|
@@ -69,12 +117,18 @@ Generate a full report
|
|
69
117
|
$ --file_prefix|-p app/models
|
70
118
|
$ --type|-t rb|js
|
71
119
|
$ --watch|-w
|
120
|
+
$ --no-open-browser|--ci
|
121
|
+
$ --start_ago|-s (e.g. 5y, 3m, 7w)
|
122
|
+
$ --minimum_churn|-c (minimum times a file must have changed to be processed)
|
72
123
|
|
73
124
|
Serve the output on http://localhost:7890
|
74
125
|
|
75
126
|
$ attractor serve
|
76
127
|
$ --file_prefix|-p app/models
|
77
128
|
$ --watch|-w
|
129
|
+
$ --no-open-browser|--ci
|
130
|
+
$ --start_ago|-s (e.g. 5y, 3m, 7w)
|
131
|
+
$ --minimum_churn|-c (minimum times a file must have changed to be processed)
|
78
132
|
|
79
133
|
## Development
|
80
134
|
|
@@ -94,3 +148,24 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/julian
|
|
94
148
|
|
95
149
|
## Logo Attribution
|
96
150
|
[Black Hole by Eynav Raphael from the Noun Project](https://thenounproject.com/term/black-hole/1043893)
|
151
|
+
|
152
|
+
## Contributors ✨
|
153
|
+
|
154
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
155
|
+
|
156
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
157
|
+
<!-- prettier-ignore-start -->
|
158
|
+
<!-- markdownlint-disable -->
|
159
|
+
<table>
|
160
|
+
<tr>
|
161
|
+
<td align="center"><a href="http://www.julianrubisch.at"><img src="https://avatars0.githubusercontent.com/u/4352208?v=4" width="100px;" alt=""/><br /><sub><b>Julian Rubisch</b></sub></a><br /><a href="https://github.com/julianrubisch/attractor/commits?author=julianrubisch" title="Code">💻</a> <a href="https://github.com/julianrubisch/attractor/commits?author=julianrubisch" title="Documentation">📖</a></td>
|
162
|
+
<td align="center"><a href="https://github.com/olimart"><img src="https://avatars3.githubusercontent.com/u/547754?v=4" width="100px;" alt=""/><br /><sub><b>Olivier</b></sub></a><br /><a href="#maintenance-olimart" title="Maintenance">🚧</a></td>
|
163
|
+
<td align="center"><a href="https://www.andrewmason.me/"><img src="https://avatars1.githubusercontent.com/u/18423853?v=4" width="100px;" alt=""/><br /><sub><b>Andrew Mason</b></sub></a><br /><a href="https://github.com/julianrubisch/attractor/commits?author=andrewmcodes" title="Code">💻</a> <a href="https://github.com/julianrubisch/attractor/pulls?q=is%3Apr+reviewed-by%3Aandrewmcodes" title="Reviewed Pull Requests">👀</a></td>
|
164
|
+
</tr>
|
165
|
+
</table>
|
166
|
+
|
167
|
+
<!-- markdownlint-enable -->
|
168
|
+
<!-- prettier-ignore-end -->
|
169
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
170
|
+
|
171
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
data/Rakefile
CHANGED
Binary file
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
});
|
1
|
+
window.type = "<%= @short_type %>";
|
2
|
+
window.serveStatic = <%= @serve_static %>;
|
3
|
+
window.filePrefix = { file_prefix: "<%= @file_prefix %>" };
|
4
|
+
window.values = <%= JSON.generate(@values) %>;
|
data/app/views/index.html.erb
CHANGED
@@ -3,67 +3,17 @@
|
|
3
3
|
<link href="https://fonts.googleapis.com/css?family=Red+Hat+Display|Red+Hat+Text&display=swap" rel="stylesheet">
|
4
4
|
<link href="stylesheets/main.css" rel="stylesheet" />
|
5
5
|
<title>Attractor Output</title>
|
6
|
+
<link rel="icon" type="image/png" href="images/attractor_favicon.png">
|
7
|
+
<script type="text/javascript">
|
8
|
+
window.types = <%= @types.to_json %>
|
9
|
+
</script>
|
6
10
|
<script src="javascripts/index.pack.js"></script>
|
7
11
|
<% if @serve_static %>
|
8
|
-
<script src="javascripts/index.js"></script>
|
12
|
+
<script src="javascripts/index<%= ".#{@short_type}" unless @short_type.nil? %>.js"></script>
|
9
13
|
<% end %>
|
10
14
|
</head>
|
11
15
|
<body class="d-flex flex-column h-100">
|
12
|
-
|
13
|
-
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
|
14
|
-
<a class="navbar-brand" href="#">
|
15
|
-
<img class="mr-3" src="images/attractor_logo.svg" alt="" width="36">
|
16
|
-
Attractor
|
17
|
-
</a>
|
18
|
-
</nav>
|
19
|
-
<div class="container">
|
20
|
-
<div class="row mt-4">
|
21
|
-
<div class="col-12">
|
22
|
-
<div class="card">
|
23
|
-
<div class="card-body">
|
24
|
-
<h5 class="card-title">Churn vs Complexity</h5>
|
25
|
-
<div class="d-flex justify-items-center">
|
26
|
-
<div id="graph"></div>
|
27
|
-
</div>
|
28
|
-
</div>
|
29
|
-
</div>
|
30
|
-
</div>
|
31
|
-
</div>
|
32
|
-
|
33
|
-
<div class="row mt-3">
|
34
|
-
<div class="col-12">
|
35
|
-
<div class="card">
|
36
|
-
<div class="card-body">
|
37
|
-
<h5 class="card-title">Refactoring Candidates</h5>
|
38
|
-
<h6 class="card-subtitle text-muted">Top 95 Percentile of Churn * Complexity</h6>
|
39
|
-
<table class="table mt-4">
|
40
|
-
<thead>
|
41
|
-
<tr>
|
42
|
-
<th scope="col">File Path</th>
|
43
|
-
<th scope="col">Churn</th>
|
44
|
-
<th scope="col">Complexity</th>
|
45
|
-
<th scope="col">Churn * Complexity</th>
|
46
|
-
</tr>
|
47
|
-
</thead>
|
48
|
-
<tbody id="suggestions-table">
|
49
|
-
<% @suggestions.each do |val| %>
|
50
|
-
<tr>
|
51
|
-
<td><%= val.file_path %></td>
|
52
|
-
<td><%= val.churn %></td>
|
53
|
-
<td><%= val.complexity %></td>
|
54
|
-
<td><%= val.churn * val.complexity %></td>
|
55
|
-
</tr>
|
56
|
-
<% end %>
|
57
|
-
<tbody>
|
58
|
-
</table>
|
59
|
-
</div>
|
60
|
-
</div>
|
61
|
-
</div>
|
62
|
-
</div>
|
63
|
-
</div>
|
64
|
-
<% else %>
|
65
|
-
<div id="react-root"></div>
|
66
|
-
<% end %>
|
16
|
+
<div id="react-root"></div>
|
67
17
|
<footer class="footer mt-auto py-3 fixed-bottom">
|
68
18
|
<div class="container d-flex justify-content-end">
|
69
19
|
<span class="mx-3"><a target="_blank" href="https://www.patreon.com/user?u=24747270">Patreon</a></span>
|
data/attractor.gemspec
CHANGED
@@ -28,7 +28,10 @@ Gem::Specification.new do |spec|
|
|
28
28
|
# Specify which files should be added to the gem when it is released.
|
29
29
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
30
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
31
|
-
`git ls-files -z`.split("\x0").reject
|
31
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
32
|
+
f.match(%r{^(src|tmp|test|spec|features|\.github)/}) ||
|
33
|
+
%w[.all-contributorsrc .rspec .rspec_status .travis.yml].include?(f)
|
34
|
+
end
|
32
35
|
end
|
33
36
|
spec.bindir = 'exe'
|
34
37
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
@@ -45,6 +48,8 @@ Gem::Specification.new do |spec|
|
|
45
48
|
spec.add_dependency 'tilt'
|
46
49
|
|
47
50
|
spec.add_development_dependency 'aruba'
|
51
|
+
spec.add_development_dependency 'attractor-javascript'
|
52
|
+
spec.add_development_dependency 'attractor-ruby'
|
48
53
|
spec.add_development_dependency 'autoprefixer-rails'
|
49
54
|
spec.add_development_dependency 'bootstrap', '~> 4.3.1'
|
50
55
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
@@ -55,5 +60,6 @@ Gem::Specification.new do |spec|
|
|
55
60
|
spec.add_development_dependency 'rake', '~> 10.0'
|
56
61
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
57
62
|
spec.add_development_dependency 'sassc'
|
63
|
+
spec.add_development_dependency 'standard'
|
58
64
|
spec.add_development_dependency 'structured_changelog'
|
59
65
|
end
|
data/lib/attractor.rb
CHANGED
@@ -1,29 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'attractor/version'
|
4
|
+
require 'attractor/gem_names'
|
5
|
+
require 'attractor/duration_parser'
|
4
6
|
require 'attractor/calculators/base_calculator'
|
5
|
-
require 'attractor/
|
6
|
-
require 'attractor/calculators/js_calculator'
|
7
|
+
require 'attractor/detectors/base_detector'
|
7
8
|
require 'attractor/reporters/base_reporter'
|
8
|
-
require 'attractor/reporters/console_reporter'
|
9
|
-
require 'attractor/reporters/html_reporter'
|
10
|
-
require 'attractor/reporters/sinatra_reporter'
|
11
9
|
require 'attractor/suggester'
|
12
10
|
require 'attractor/watcher'
|
13
11
|
|
12
|
+
Dir[File.join(__dir__, 'attractor', 'reporters', '*.rb')].each do |file|
|
13
|
+
next if file.start_with?('base')
|
14
|
+
|
15
|
+
require file
|
16
|
+
end
|
17
|
+
|
14
18
|
module Attractor
|
15
19
|
class Error < StandardError; end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
@registry_entries = {}
|
22
|
+
|
23
|
+
def register(registry_entry)
|
24
|
+
@registry_entries[registry_entry.type] = registry_entry
|
25
|
+
end
|
26
|
+
|
27
|
+
def calculators_for_type(type, **options)
|
28
|
+
registry_entry_for_type = @registry_entries[type]
|
29
|
+
|
30
|
+
return { type => registry_entry_for_type.calculator_class.new(**options) } if type
|
31
|
+
|
32
|
+
|
33
|
+
Hash[@registry_entries.map do |type, entry|
|
34
|
+
[type, entry.calculator_class.new(**options)] if entry.detector_class.new.detect
|
35
|
+
end]
|
26
36
|
end
|
27
37
|
|
28
38
|
module_function :calculators_for_type
|
39
|
+
module_function :register
|
40
|
+
end
|
41
|
+
|
42
|
+
Attractor::GemNames.new.to_a.each do |gem_name|
|
43
|
+
require "attractor/#{gem_name}"
|
29
44
|
end
|
@@ -7,10 +7,13 @@ require 'attractor/value'
|
|
7
7
|
module Attractor
|
8
8
|
# calculates churn and complexity
|
9
9
|
class BaseCalculator
|
10
|
-
|
10
|
+
attr_reader :type
|
11
|
+
|
12
|
+
def initialize(file_prefix: '', file_extension: 'rb', minimum_churn_count: 3, start_ago: '5y')
|
11
13
|
@file_prefix = file_prefix
|
12
14
|
@file_extension = file_extension
|
13
15
|
@minimum_churn_count = minimum_churn_count
|
16
|
+
@start_date = Date.today - Attractor::DurationParser.new(start_ago).duration
|
14
17
|
end
|
15
18
|
|
16
19
|
def calculate
|
@@ -18,7 +21,7 @@ module Attractor
|
|
18
21
|
file_extension: @file_extension,
|
19
22
|
file_prefix: @file_prefix,
|
20
23
|
minimum_churn_count: @minimum_churn_count,
|
21
|
-
start_date:
|
24
|
+
start_date: @start_date
|
22
25
|
).report(false)
|
23
26
|
|
24
27
|
churn[:churn][:changes].map do |change|
|
data/lib/attractor/cli.rb
CHANGED
@@ -7,40 +7,48 @@ require 'attractor'
|
|
7
7
|
module Attractor
|
8
8
|
# contains methods implementing the CLI
|
9
9
|
class CLI < Thor
|
10
|
+
shared_options = [[:file_prefix, aliases: :p],
|
11
|
+
[:watch, aliases: :w, type: :boolean],
|
12
|
+
[:minimum_churn, aliases: :c, type: :numeric, default: 3],
|
13
|
+
[:start_ago, aliases: :s, type: :string, default: '5y'],
|
14
|
+
[:type, aliases: :t]]
|
15
|
+
|
16
|
+
advanced_options = [[:format, aliases: :f, default: 'html'],
|
17
|
+
[:no_open_browser, type: :boolean],
|
18
|
+
[:ci, type: :boolean]]
|
19
|
+
|
10
20
|
desc 'calc', 'Calculates churn and complexity for all ruby files in current directory'
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
shared_options.each do |shared_option|
|
22
|
+
option(*shared_option)
|
23
|
+
end
|
14
24
|
def calc
|
15
25
|
file_prefix = options[:file_prefix]
|
16
|
-
calculators = Attractor.calculators_for_type(options[:type], file_prefix)
|
17
26
|
if options[:watch]
|
18
27
|
puts 'Listening for file changes...'
|
19
|
-
Attractor::ConsoleReporter.new(file_prefix: file_prefix, calculators: calculators).watch
|
28
|
+
Attractor::ConsoleReporter.new(file_prefix: file_prefix, calculators: calculators(options)).watch
|
20
29
|
else
|
21
|
-
Attractor::ConsoleReporter.new(file_prefix: file_prefix, calculators: calculators).report
|
30
|
+
Attractor::ConsoleReporter.new(file_prefix: file_prefix, calculators: calculators(options)).report
|
22
31
|
end
|
23
32
|
rescue RuntimeError => e
|
24
33
|
puts "Runtime error: #{e.message}"
|
25
34
|
end
|
26
35
|
|
27
36
|
desc 'report', 'Generates an HTML report'
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
option :type, aliases: :t
|
37
|
+
(shared_options + advanced_options).each do |option|
|
38
|
+
option(*option)
|
39
|
+
end
|
32
40
|
def report
|
33
41
|
file_prefix = options[:file_prefix]
|
34
|
-
|
42
|
+
open_browser = !(options[:no_open_browser] || options[:ci])
|
35
43
|
if options[:watch]
|
36
44
|
puts 'Listening for file changes...'
|
37
|
-
Attractor::HtmlReporter.new(file_prefix: file_prefix, calculators: calculators).watch
|
45
|
+
Attractor::HtmlReporter.new(file_prefix: file_prefix, calculators: calculators(options), open_browser: open_browser).watch
|
38
46
|
else
|
39
47
|
case options[:format]
|
40
48
|
when 'html'
|
41
|
-
Attractor::HtmlReporter.new(file_prefix: file_prefix, calculators: calculators).report
|
49
|
+
Attractor::HtmlReporter.new(file_prefix: file_prefix, calculators: calculators(options), open_browser: open_browser).report
|
42
50
|
else
|
43
|
-
Attractor::HtmlReporter.new(file_prefix: file_prefix, calculators: calculators).report
|
51
|
+
Attractor::HtmlReporter.new(file_prefix: file_prefix, calculators: calculators(options), open_browser: open_browser).report
|
44
52
|
end
|
45
53
|
end
|
46
54
|
rescue RuntimeError => e
|
@@ -48,24 +56,32 @@ module Attractor
|
|
48
56
|
end
|
49
57
|
|
50
58
|
desc 'serve', 'Serves the report on localhost'
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
option :type, aliases: :t
|
59
|
+
(shared_options + advanced_options).each do |option|
|
60
|
+
option(*option)
|
61
|
+
end
|
55
62
|
def serve
|
56
63
|
file_prefix = options[:file_prefix]
|
57
|
-
|
64
|
+
open_browser = !(options[:no_open_browser] || options[:ci])
|
58
65
|
if options[:watch]
|
59
66
|
puts 'Listening for file changes...'
|
60
|
-
Attractor::SinatraReporter.new(file_prefix: file_prefix, calculators: calculators).watch
|
67
|
+
Attractor::SinatraReporter.new(file_prefix: file_prefix, calculators: calculators(options), open_browser: open_browser).watch
|
61
68
|
else
|
62
69
|
case options[:format]
|
63
70
|
when 'html'
|
64
|
-
Attractor::SinatraReporter.new(file_prefix: file_prefix, calculators: calculators).report
|
71
|
+
Attractor::SinatraReporter.new(file_prefix: file_prefix, calculators: calculators(options), open_browser: open_browser).report
|
65
72
|
else
|
66
|
-
Attractor::SinatraReporter.new(file_prefix: file_prefix, calculators: calculators).report
|
73
|
+
Attractor::SinatraReporter.new(file_prefix: file_prefix, calculators: calculators(options), open_browser: open_browser).report
|
67
74
|
end
|
68
75
|
end
|
69
76
|
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def calculators(options)
|
81
|
+
Attractor.calculators_for_type(options[:type],
|
82
|
+
file_prefix: options[:file_prefix],
|
83
|
+
minimum_churn_count: options[:minimum_churn],
|
84
|
+
start_ago: options[:start_ago])
|
85
|
+
end
|
70
86
|
end
|
71
87
|
end
|