cli_spinnable 0.1 → 0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b57d77c25a5bb808706cb92487a5877fa2c32121
4
- data.tar.gz: f59c00a22d6b5958b6a2183f10fbd6a1728ffa11
3
+ metadata.gz: bb9427d5e29feac4435264fc98494a1ec200a5f8
4
+ data.tar.gz: 88d98f350933a6fe8f4fc9e5e1e27f8090af2e41
5
5
  SHA512:
6
- metadata.gz: 64cd82f07433483e87807de0268ceec2cb175f129b5adacad2d4bea007c09b8d4c72230b0434d312361db7de0a5bd2085337e1d8a496a5d3d454b78080bb03d8
7
- data.tar.gz: 0b77ed47dde390e9977b9549c9ee200eb9b7a2c4c924e698366e36ccb07943437e2103fe12d236cd0421d095901eefb7cb1a6c7681a6ec53404e7e84c0565cf6
6
+ metadata.gz: c190c8978e80063e623dafa4d5113af7f094ee5a28d40f31ff95299f54cfe4efbe23289c52694c2b841d457107a3be81d224ff5c3cdd51dcfb329eb13b245bb3
7
+ data.tar.gz: 4354df4d30830b93081820d8c07acd8fc228326995750d7628b4509f9d264870a1ec4abd546d137a81bf7a683fb836ccbe0d7ff985c67428d7c012ccfb4c8825
@@ -1,34 +1,40 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
+ ## This example shows different ways of accessing the `.with_spinner` method.
4
+
3
5
  require 'cli_spinnable'
4
6
 
5
- class Foo
7
+ # 1. Use `CliSpinnable.with_spinner` directly.
8
+ CliSpinnable.with_spinner do |cli|
9
+ cli.print 'Downloading something'
10
+ sleep 1
11
+ cli.tick
12
+ end
13
+
14
+ # 2. Create own module and extend it with CliSpinnable.
15
+ # This way you will have own namespace for `.with_spinner` method.
16
+ module Foo
17
+ extend CliSpinnable
18
+ end
19
+
20
+ Foo.with_spinner do |cli|
21
+ cli.print 'Downloading something'
22
+ sleep 1
23
+ cli.tick
24
+ end
25
+
26
+ # 3. Include CliSpinnable module in own class.
27
+ # This way you can access `with_spinner` method within that class.
28
+ class Bar
6
29
  include CliSpinnable
7
30
 
8
31
  def call
9
- puts 'HAPPY RUN (ending with success):'
10
32
  with_spinner do |cli|
11
33
  cli.print 'Downloading something'
12
34
  sleep 1
13
- cli.print '...downloaded 1MB'
14
- cli.tick
15
- cli.print 'Processing data'
16
- sleep 1
17
- cli.tick
18
- end
19
-
20
- puts 'SAD RUN (ending with fail):'
21
- with_spinner do |cli|
22
- cli.print 'Downloading something'
23
- sleep 1
24
- cli.print '...downloaded 1MB'
25
- cli.tick
26
- cli.print 'Processing data'
27
- sleep 1
28
- 1 / 0
29
35
  cli.tick
30
36
  end
31
37
  end
32
38
  end
33
39
 
34
- Foo.new.call
40
+ Bar.new.call
@@ -2,12 +2,12 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
3
  require 'cli_spinnable'
4
4
 
5
- module Foo
5
+ module Cli
6
6
  extend CliSpinnable
7
7
  end
8
8
 
9
- puts 'HAPPY RUN (ending with success):'
10
- Foo.with_spinner do |cli|
9
+ puts 'HAPPY RUN (should succeed):'
10
+ Cli.with_spinner do |cli|
11
11
  cli.print 'Downloading something'
12
12
  sleep 1
13
13
  cli.print '...downloaded 1MB'
@@ -17,14 +17,14 @@ Foo.with_spinner do |cli|
17
17
  cli.tick
18
18
  end
19
19
 
20
- puts 'SAD RUN (ending with fail):'
21
- Foo.with_spinner do |cli|
20
+ puts 'SAD RUN (should fail):'
21
+ Cli.with_spinner do |cli|
22
22
  cli.print 'Downloading something'
23
23
  sleep 1
24
24
  cli.print '...downloaded 1MB'
25
25
  cli.tick
26
26
  cli.print 'Processing data'
27
27
  sleep 1
28
- 1 / 0
29
- cli.tick
28
+ 1 / 0 # produces exception
29
+ cli.tick # this will not be reached
30
30
  end
@@ -2,27 +2,38 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
3
  require 'cli_spinnable'
4
4
 
5
- include CliSpinnable
5
+ module Cli
6
+ extend CliSpinnable
7
+ end
8
+
9
+ # Close the block before reading from input.
6
10
 
7
- puts 'HAPPY RUN (ending with success):'
8
- with_spinner do |cli|
11
+ # Good:
12
+ Cli.with_spinner do |cli|
9
13
  cli.print 'Downloading something'
10
14
  sleep 1
11
- cli.print '...downloaded 1MB'
12
15
  cli.tick
13
- cli.print 'Processing data'
16
+ end
17
+
18
+ print 'Enter name: '
19
+ name = gets.chomp
20
+
21
+ Cli.with_spinner do |cli|
22
+ cli.print "Doing something with name #{name}"
14
23
  sleep 1
15
24
  cli.tick
16
25
  end
17
26
 
18
- puts 'SAD RUN (ending with fail):'
19
- with_spinner do |cli|
27
+ # Bad:
28
+ Cli.with_spinner do |cli|
20
29
  cli.print 'Downloading something'
21
30
  sleep 1
22
- cli.print '...downloaded 1MB'
23
31
  cli.tick
24
- cli.print 'Processing data'
32
+
33
+ print 'Enter name: '
34
+ name = gets.chomp
35
+
36
+ cli.print "Doing something with name #{name}"
25
37
  sleep 1
26
- 1 / 0
27
38
  cli.tick
28
39
  end
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'cli_spinnable'
4
+
5
+ module Cli
6
+ extend CliSpinnable
7
+ end
8
+
9
+ # Don't print multiline strings inside `with_spinner` block.
10
+
11
+ # Good:
12
+ Cli.with_spinner do |cli|
13
+ cli.print 'Downloading something'
14
+ sleep 1
15
+ cli.tick
16
+ end
17
+
18
+ print "Multiline\nstring"
19
+
20
+ # Bad:
21
+ Cli.with_spinner do |cli|
22
+ cli.print 'Downloading something'
23
+ sleep 1
24
+ cli.tick
25
+ print "Multiline\nstring"
26
+ end
27
+ s
28
+ # Bad:
29
+
30
+ Cli.with_spinner do |cli|
31
+ cli.print 'Downloading something'
32
+ sleep 1
33
+ cli.tick
34
+ cli.print "Multiline\nstring"
35
+ end
@@ -6,16 +6,24 @@ require 'cli_spinnable/line'
6
6
  require 'cli_spinnable/writer'
7
7
 
8
8
  module CliSpinnable
9
- def with_spinner
10
- writer = Writer.new(STDOUT, Line.new)
11
- yield writer
12
- writer.finalize
13
- self
14
- rescue CliSpinnableError => e
15
- raise e
16
- rescue StandardError => e
17
- writer.failure
18
- writer.finalize
19
- raise e
9
+ module Methods
10
+ def with_spinner
11
+ writer = Writer.new(STDOUT, Line.new)
12
+ yield writer
13
+ writer.finalize
14
+ self
15
+ rescue CliSpinnableError => e
16
+ raise e
17
+ rescue StandardError => e
18
+ writer.failure
19
+ writer.finalize
20
+ raise e
21
+ end
22
+ end
23
+
24
+ include Methods
25
+
26
+ class << self
27
+ include Methods
20
28
  end
21
29
  end
@@ -1,3 +1,3 @@
1
1
  module CliSpinnable
2
- VERSION = '0.1'.freeze
2
+ VERSION = '0.2'.freeze
3
3
  end
@@ -27,12 +27,12 @@ module CliSpinnable
27
27
  def failure
28
28
  push(:sign=, :fail)
29
29
  push(:newline=, true)
30
+ push(:str=, '')
30
31
  self
31
32
  end
32
33
 
33
34
  def finalize
34
35
  push(:sign=, :blank)
35
- push(:str=, '')
36
36
  finalize_session
37
37
  self
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli_spinnable
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Krzysztof Maicher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-17 00:00:00.000000000 Z
11
+ date: 2016-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,7 @@ files:
132
132
  - examples/example1.rb
133
133
  - examples/example2.rb
134
134
  - examples/example3.rb
135
+ - examples/example4.rb
135
136
  - lib/cli_spinnable.rb
136
137
  - lib/cli_spinnable/cli_spinnable_error.rb
137
138
  - lib/cli_spinnable/line.rb
@@ -159,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
160
  version: '0'
160
161
  requirements: []
161
162
  rubyforge_project:
162
- rubygems_version: 2.4.8
163
+ rubygems_version: 2.5.1
163
164
  signing_key:
164
165
  specification_version: 4
165
166
  summary: CliSpinnable, a module that enriches ruby command line interface with rotating