attractor 1.0.0 → 1.2.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/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 +5 -1
- data/lib/attractor.rb +27 -9
- data/lib/attractor/calculators/base_calculator.rb +5 -2
- data/lib/attractor/calculators/js_calculator.rb +3 -2
- data/lib/attractor/calculators/ruby_calculator.rb +3 -2
- data/lib/attractor/cli.rb +38 -22
- data/lib/attractor/detectors/base_detector.rb +7 -0
- data/lib/attractor/detectors/js_detector.rb +11 -0
- data/lib/attractor/detectors/ruby_detector.rb +11 -0
- data/lib/attractor/duration_parser.rb +27 -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 -3
- data/lib/attractor/suggester.rb +1 -1
- data/lib/attractor/version.rb +1 -1
- metadata +21 -4
- data/.rspec +0 -3
- data/.travis.yml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 118ead51f4c2d1b543e923e93a0080d56e80cc814bfa0745b9d9400baef01c12
|
4
|
+
data.tar.gz: 4ed35b0269e8a5b1f5d81485283102a8bfd5e07effd82f7ad9684747fc14d409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f51eb3d48a28ee8d0db31fff0d1228ea0945db99445cf55da0cb8f5b9cbe791554441480160d847c5e9508bda85875dcac7d8c83f703c7ddaf7953919275df3
|
7
|
+
data.tar.gz: 882c38655cd2b65c6d4732d2d7907a69887eff1c6ff1c6804df8336861e72becf1518d161602a1dfe6b6bd108f4c95b88b582bed615ba8f989f3b780789d1452
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## RELEASE 1.2.0
|
2
|
+
|
3
|
+
* FEATURE: Backport React to static output
|
4
|
+
|
5
|
+
## RELEASE 1.1.1
|
6
|
+
|
7
|
+
* ENHANCEMENT: `--minimum_churn` and `--start_ago` CLI options
|
8
|
+
|
9
|
+
## RELEASE 1.1.0
|
10
|
+
|
11
|
+
* FEATURE: Auto-detect ruby and js projects
|
12
|
+
|
13
|
+
## RELEASE 1.0.2
|
14
|
+
|
15
|
+
* ENHANCEMENT: make launching of browser optional
|
16
|
+
|
17
|
+
## RELEASE 1.0.1
|
18
|
+
|
19
|
+
* FIX: fix sinatra reporter
|
20
|
+
|
1
21
|
## RELEASE 1.0.0
|
2
22
|
|
3
23
|
* BREAKING: Add Javascript / ES6 support via typhonjs-escomplex
|
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!
|
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) }
|
@@ -55,5 +58,6 @@ Gem::Specification.new do |spec|
|
|
55
58
|
spec.add_development_dependency 'rake', '~> 10.0'
|
56
59
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
57
60
|
spec.add_development_dependency 'sassc'
|
61
|
+
spec.add_development_dependency 'standard'
|
58
62
|
spec.add_development_dependency 'structured_changelog'
|
59
63
|
end
|
data/lib/attractor.rb
CHANGED
@@ -1,27 +1,45 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'attractor/version'
|
4
|
+
require 'attractor/duration_parser'
|
4
5
|
require 'attractor/calculators/base_calculator'
|
5
|
-
require 'attractor/
|
6
|
-
require 'attractor/calculators/js_calculator'
|
6
|
+
require 'attractor/detectors/base_detector'
|
7
7
|
require 'attractor/reporters/base_reporter'
|
8
|
-
require 'attractor/reporters/console_reporter'
|
9
|
-
require 'attractor/reporters/html_reporter'
|
10
|
-
require 'attractor/reporters/sinatra_reporter'
|
11
8
|
require 'attractor/suggester'
|
12
9
|
require 'attractor/watcher'
|
13
10
|
|
11
|
+
Dir[File.join(__dir__, 'attractor', 'calculators', '*.rb')].each do |file|
|
12
|
+
next if file.start_with?('base')
|
13
|
+
|
14
|
+
require file
|
15
|
+
end
|
16
|
+
|
17
|
+
Dir[File.join(__dir__, 'attractor', 'detectors', '*.rb')].each do |file|
|
18
|
+
next if file.start_with?('base')
|
19
|
+
|
20
|
+
require file
|
21
|
+
end
|
22
|
+
|
23
|
+
Dir[File.join(__dir__, 'attractor', 'reporters', '*.rb')].each do |file|
|
24
|
+
next if file.start_with?('base')
|
25
|
+
|
26
|
+
require file
|
27
|
+
end
|
28
|
+
|
14
29
|
module Attractor
|
15
30
|
class Error < StandardError; end
|
16
31
|
|
17
|
-
def calculators_for_type(type,
|
32
|
+
def calculators_for_type(type, **options)
|
18
33
|
case type
|
19
34
|
when 'js'
|
20
|
-
{ 'js' => JsCalculator.new(
|
35
|
+
{ 'js' => JsCalculator.new(**options) }
|
21
36
|
when 'rb'
|
22
|
-
{ 'rb' => RubyCalculator.new(
|
37
|
+
{ 'rb' => RubyCalculator.new(**options) }
|
23
38
|
else
|
24
|
-
{
|
39
|
+
{}.tap do |hash|
|
40
|
+
hash['rb'] = RubyCalculator.new(**options) if RubyDetector.new.detect
|
41
|
+
hash['js'] = JsCalculator.new(**options) if JsDetector.new.detect
|
42
|
+
end
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
@@ -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|
|
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
module Attractor
|
4
4
|
class JsCalculator < BaseCalculator
|
5
|
-
def initialize(file_prefix: '', minimum_churn_count: 3)
|
6
|
-
super(file_prefix: file_prefix, file_extension: '(js|jsx)', minimum_churn_count: minimum_churn_count)
|
5
|
+
def initialize(file_prefix: '', minimum_churn_count: 3, start_ago: 365 * 5)
|
6
|
+
super(file_prefix: file_prefix, file_extension: '(js|jsx)', minimum_churn_count: minimum_churn_count, start_ago: start_ago)
|
7
|
+
@type = "JavaScript"
|
7
8
|
end
|
8
9
|
|
9
10
|
def calculate
|
@@ -4,8 +4,9 @@ require 'flog'
|
|
4
4
|
|
5
5
|
module Attractor
|
6
6
|
class RubyCalculator < BaseCalculator
|
7
|
-
def initialize(file_prefix: '', minimum_churn_count: 3)
|
8
|
-
super(file_prefix: file_prefix, file_extension: 'rb', minimum_churn_count: minimum_churn_count)
|
7
|
+
def initialize(file_prefix: '', minimum_churn_count: 3, start_ago: 365 * 5)
|
8
|
+
super(file_prefix: file_prefix, file_extension: 'rb', minimum_churn_count: minimum_churn_count, start_ago: start_ago)
|
9
|
+
@type = "Ruby"
|
9
10
|
end
|
10
11
|
|
11
12
|
def calculate
|
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
|