sneaker 0.1.2 → 0.2.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: 0fbcbb693edd822efe433d69310ff96d8192abacafb06564de837ad7ccd343a6
4
- data.tar.gz: 4af43a5663e5b3d258410f187390ca3c609fe17b28a43f51d3a8c2828676c974
3
+ metadata.gz: cc5e413d39b771e9d0661043fc5f367a974567c0f28a98446abab9bceb21214b
4
+ data.tar.gz: 31007058be742bb8be1a8c6618cb6c3d9e74ef95cfd0decb398c309c63d8886b
5
5
  SHA512:
6
- metadata.gz: 833bd033727083d7046e75133c35d1007a087ac6669a3c483bde22ccf9de6ba358fa5fc15a7f12825b8804246d133d203de0b86a82cb7d8fe471cc8f3a85fd2d
7
- data.tar.gz: 96d82e435f8095756270473098e7478078a78581a5a08737cd21ce1c569703e4670224e8a9f4569a67a4e242413fc04dd5ebab4692ebb0d1e367a870a7470139
6
+ metadata.gz: 47d09a086a3a6db4a0dd3c3c0fcf29b32126fd93bfc397a969bab72f0dfc46f17697394ad8a97a7e34e62324bfcfcc316997b3176b79701992bb65266845dc76
7
+ data.tar.gz: d817b5136613743cf2e8cfe63ce32830e2155885fb7be0ba89bce9343d9c65f1667874d8e04f6a7470f2225a9de0af972d84c3a5b7f67709c28669b550f73c37
@@ -33,7 +33,7 @@ module Sneaker
33
33
 
34
34
  def multiple_execute
35
35
  stages = Stage.all
36
- presentation = Presentation.new(stages.map(&:name))
36
+ presentation = Presentation.create(stages.map(&:name))
37
37
  threads = []
38
38
  mutex = Mutex.new
39
39
 
@@ -1,47 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tty-table'
4
3
  require 'tty-cursor'
5
- require 'pastel'
4
+
5
+ require 'sneaker/presentation/csv'
6
+ require 'sneaker/presentation/table'
6
7
 
7
8
  module Sneaker
8
9
  class Presentation
10
+ def self.create(stages)
11
+ klass = case ENV.fetch('format', '').downcase
12
+ when 'csv'
13
+ CSV
14
+ else
15
+ Table
16
+ end
17
+
18
+ klass.new(stages)
19
+ end
20
+
9
21
  def initialize(stages)
10
- @table = []
11
22
  @stages = stages.sort
12
23
  @cursor = TTY::Cursor
13
- @pastel = Pastel.new
14
-
15
- @stages.each do |stage|
16
- @table << [formatted_stage(stage), @pastel.inverse('loading...')]
17
- end
18
24
 
25
+ initialize_results
19
26
  draw
20
27
  end
21
28
 
22
29
  def set(stage, result)
23
- set_in_table(stage, result)
30
+ @results[stage] = formatted_result(result)
24
31
 
25
32
  redraw
26
33
  end
27
34
 
28
35
  private
29
36
 
30
- def formatted_stage(stage)
31
- @pastel.bold(stage)
37
+ def initialize_results
38
+ @results = {}
39
+
40
+ @stages.each do |stage|
41
+ @results[stage] = loading_result
42
+ end
32
43
  end
33
44
 
34
- def formatted_result(result)
35
- return @pastel.on_red('!error') if result == :error
36
- return @pastel.red(result) if result == 'false'
37
- return @pastel.green(result) if result == 'true'
38
- result
45
+ def loading_result
46
+ ''
39
47
  end
40
48
 
41
- def set_in_table(stage, result)
42
- @table.each do |row|
43
- row[1] = formatted_result(result) if row.first == formatted_stage(stage)
44
- end
49
+ def formatted_result(result)
50
+ result
45
51
  end
46
52
 
47
53
  def redraw
@@ -50,13 +56,8 @@ module Sneaker
50
56
  end
51
57
 
52
58
  def clear
53
- print @cursor.up(@tty_table.rows_size + 2)
59
+ print @cursor.up(output_lines)
54
60
  print @cursor.clear_line_after
55
61
  end
56
-
57
- def draw
58
- @tty_table = TTY::Table.new(@table)
59
- puts @tty_table.render(:unicode)
60
- end
61
62
  end
62
63
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sneaker
4
+ class Presentation
5
+ class CSV < Presentation
6
+ private
7
+
8
+ def output_lines
9
+ @results.size
10
+ end
11
+
12
+ def draw
13
+ @results.each do |result|
14
+ puts result.join(',')
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty-table'
4
+ require 'pastel'
5
+
6
+ module Sneaker
7
+ class Presentation
8
+ class Table < Presentation
9
+ def initialize(stages)
10
+ @pastel = Pastel.new
11
+
12
+ super
13
+ end
14
+
15
+ private
16
+
17
+ def formatted_stage(stage)
18
+ @pastel.bold(stage)
19
+ end
20
+
21
+ def formatted_result(result)
22
+ return @pastel.on_red('!error') if result == :error
23
+ return @pastel.red(result) if result == 'false'
24
+ return @pastel.green(result) if result == 'true'
25
+
26
+ result
27
+ end
28
+
29
+ def output_lines
30
+ @tty_table.rows_size + 2
31
+ end
32
+
33
+ def draw
34
+ @tty_table = TTY::Table.new(results_table)
35
+ puts @tty_table.render(:unicode)
36
+ end
37
+
38
+ def results_table
39
+ @results.reduce([]) do |results_table, stage_with_result|
40
+ results_table << [
41
+ formatted_stage(stage_with_result.first),
42
+ stage_with_result.last
43
+ ]
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Sneaker
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/sneaker.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.15"
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
26
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sneaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ideas4allInnovation
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +171,8 @@ files:
171
171
  - lib/sneaker.rb
172
172
  - lib/sneaker/command.rb
173
173
  - lib/sneaker/presentation.rb
174
+ - lib/sneaker/presentation/csv.rb
175
+ - lib/sneaker/presentation/table.rb
174
176
  - lib/sneaker/stage.rb
175
177
  - lib/sneaker/version.rb
176
178
  - sneaker.gemspec