attractor 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dd203412f941afde6477504c01a7d2350edacf9e5e7f172ee3e886f8e1cdd4e
4
- data.tar.gz: 6040857f9c34c52456e644fd06acdee1b760c48dcc9572617be529a783153493
3
+ metadata.gz: 4f0de58545a6ef7aab553b1d35bf6141c89b0cabbb6941d8aaae17954123c318
4
+ data.tar.gz: 8d5cc1fa551799419a86ec11818f96d5dbcbe2f44d0bd5e4f2c2cb0c9f9525ae
5
5
  SHA512:
6
- metadata.gz: d50af1838bd60d61cc0998506e0e84906bd2dc41b35b57a185e059b4e8f27553f7315b912670f4d0896e994d6227bc84926764948c3b452466c80bfc740392ee
7
- data.tar.gz: 0122f559b3cb3e46c5038615c1bf155b69fb6376c512f3190b49300ca88b958693848948f3a479e4aa400a8bf070d1dc985fe495f74bf3b5a966544a9ec4c2d2
6
+ metadata.gz: e69218d04e69b8ddb84d64c9032ce48285089d0e79d7c92e4513708cd3ec088c7d747dd955d2d53ea983a3b45d7ccca9aad29c449d1e25e2c608f9f3bcb6c65c
7
+ data.tar.gz: d273824cc41ecbc7560fe0c18b8765fe04bfad3df461d10bc3a7ab7803c02c6416d2025971d8237bcdaa53a428b6623f7e33d817593d9b38426ce053c035cb1b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## RELEASE 0.3.0
2
+
3
+ * FEATURE: Rack live reload
4
+
1
5
  ## RELEASE 0.2.1
2
6
 
3
7
  * ENHANCEMENT: automatically open browser window
data/README.md CHANGED
@@ -52,6 +52,16 @@ Generate a full report
52
52
  $ --file_prefix|-p app/models
53
53
  $ --watch|-w
54
54
 
55
+ Serve the output on http://localhost:7890
56
+
57
+ $ attractor serve
58
+ $ --file_prefix|-p app/models
59
+ $ --watch|-w
60
+
61
+ ### Live Reloading
62
+
63
+ 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.
64
+
55
65
  ## Development
56
66
 
57
67
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/attractor.gemspec CHANGED
@@ -38,6 +38,8 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency 'flog', '~> 4.0'
39
39
  spec.add_dependency 'launchy'
40
40
  spec.add_dependency 'listen', '~> 3.0'
41
+ spec.add_dependency 'rack'
42
+ spec.add_dependency 'rack-livereload'
41
43
  spec.add_dependency 'thor'
42
44
  spec.add_dependency 'tilt'
43
45
 
data/lib/attractor/cli.rb CHANGED
@@ -36,5 +36,23 @@ module Attractor
36
36
  end
37
37
  end
38
38
  end
39
+
40
+ desc 'serve', 'Serves the report on localhost'
41
+ option :format, aliases: :f, default: 'html'
42
+ option :file_prefix, aliases: :p
43
+ option :watch, aliases: :w, type: :boolean
44
+ def serve
45
+ if options[:watch]
46
+ puts 'Listening for file changes...'
47
+ Attractor::RackReporter.new(file_prefix: options[:file_prefix]).watch
48
+ else
49
+ case options[:format]
50
+ when 'html'
51
+ Attractor::RackReporter.new(file_prefix: options[:file_prefix]).report
52
+ else
53
+ Attractor::RackReporter.new(file_prefix: options[:file_prefix]).report
54
+ end
55
+ end
56
+ end
39
57
  end
40
58
  end
@@ -3,6 +3,8 @@
3
3
  require 'descriptive_statistics/safe'
4
4
  require 'fileutils'
5
5
  require 'launchy'
6
+ require 'rack'
7
+ require 'rack/livereload'
6
8
  require 'tilt'
7
9
 
8
10
  module Attractor
@@ -25,6 +27,14 @@ module Attractor
25
27
  def report
26
28
  @suggestions = @suggester.suggest
27
29
  end
30
+
31
+ def render
32
+ 'Attractor'
33
+ end
34
+
35
+ def serve
36
+ @suggestions = @suggester.suggest
37
+ end
28
38
  end
29
39
 
30
40
  # console reporter
@@ -51,15 +61,55 @@ module Attractor
51
61
  super
52
62
 
53
63
  puts 'Generating an HTML report'
54
- template = Tilt.new(File.expand_path('../templates/index.html.erb', __dir__))
55
- output = template.render self
56
64
 
57
65
  FileUtils.mkdir_p './attractor_output'
58
66
 
59
- File.open('./attractor_output/index.html', 'w') { |file| file.write(output) }
67
+ File.open('./attractor_output/index.html', 'w') { |file| file.write(render) }
60
68
  puts "Generated HTML report at #{File.expand_path './attractor_output/index.html'}"
61
69
 
62
- Launchy.open(File.expand_path './attractor_output/index.html')
70
+ Launchy.open(File.expand_path('./attractor_output/index.html'))
71
+ end
72
+
73
+ def render
74
+ template = Tilt.new(File.expand_path('../templates/index.html.erb', __dir__))
75
+ template.render self
76
+ end
77
+ end
78
+
79
+ # serving the HTML locally
80
+ class RackReporter < Reporter
81
+ def report
82
+ super
83
+
84
+ app = serve_via_rack
85
+
86
+ Rack::Handler::WEBrick.run app, Port: 7890
87
+ end
88
+
89
+ def render
90
+ template = Tilt.new(File.expand_path('../templates/index.html.erb', __dir__))
91
+ template.render self
92
+ end
93
+
94
+ def watch
95
+ @suggestions = @suggester.suggest
96
+
97
+ app = serve_via_rack
98
+
99
+ Rack::Handler::WEBrick.run Rack::LiveReload.new(app), Port: 7890
100
+ end
101
+
102
+ private
103
+
104
+ def serve_via_rack
105
+ app = lambda do |_env|
106
+ [200, { 'Content-Type' => 'text/html' }, [render]]
107
+ end
108
+
109
+ puts 'Serving attractor at http://localhost:7890'
110
+ Launchy.open('http://localhost:7890')
111
+
112
+ app
63
113
  end
64
114
  end
65
115
  end
@@ -1,3 +1,3 @@
1
1
  module Attractor
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  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: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Rubisch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2019-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: churn
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-livereload
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: thor
85
113
  requirement: !ruby/object:Gem::Requirement