spin_to_win 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 4728b0bd3d8e135d747b274a2d40663869bb75d0
4
- data.tar.gz: 80629e5dbac4d58bb5774561ff1a5752ee83a76b
3
+ metadata.gz: 7b84f4987c35b23cc49413617bdf1043c94498b3
4
+ data.tar.gz: e65cebf46ab31258ffe4ff7f1c7bf99487c9a6ba
5
5
  SHA512:
6
- metadata.gz: 7b482c290ec777e4f8a1808bf776cceca1c8c2ee7b39f1523c65f425c490ca063ab160d11c6aad845d36d5d199a0735cc10587e364142b3070420f4759a58c67
7
- data.tar.gz: 751c8e491815a5249be4135e46445b3afb1962681e5d9e6cd468cdef8885d2924184a5af161980a26eaab45275b6d0e08eb95927acb5b5fb9b67772150fbb1ef
6
+ metadata.gz: 10b6315dd2a62e925a2d0be6c4c8da9c344fcd0eb71efa4d365efa586b2b0b2cbcfc3e3cef229aa77c70ed122fbc28372e0c1f558a40006c29349d5f00901a6e
7
+ data.tar.gz: 40335c0824f51195f50e5aedf7b405493a51310d6ee3db2de606558d25cfb2bf9a487a2b3d2f929a193e62073f0ff52a18d747ab175bee6f5707f8a3fe2c303b
data/README.md CHANGED
@@ -3,23 +3,23 @@
3
3
  Simple ruby spinner that allows on the fly notifications in the format of:
4
4
 
5
5
  :title :spinner :finished of :todo [:banner]
6
-
7
- The bare bones spinner is
8
6
 
9
- SpinToWin.with_spinner { sleep 1 }
10
-
7
+ The bare bones spinner is
8
+
9
+ SpinToWin.with_spinner { sleep 1 }
10
+
11
11
  \
12
12
 
13
- With a title is
13
+ With a title is
14
14
 
15
15
  SpinToWin.with_spinner('Zzzz') { sleep 1 }`
16
-
16
+
17
17
  Zzzz \
18
18
 
19
19
  With a title and banner:
20
20
 
21
21
  SpinToWin.with_spinner('Zzzz') { |spinner| spinner.banner('sleepy'); sleep 1 }
22
-
22
+
23
23
  Zzzz \ [sleepy]
24
24
 
25
25
  The title is persistent but the banner can be changed with calls to the yielded `spinner`
@@ -28,22 +28,54 @@ With title, banner, and todos
28
28
 
29
29
  SpinToWin.with_spinner('Zzzz') do |spinner|
30
30
  spinner.increment_todo!(3)
31
-
31
+
32
32
  spinner.banner('snore')
33
33
  sleep 1
34
34
  spinner.increment_done!
35
-
35
+
36
36
  spinner.banner('dream')
37
37
  sleep 1
38
38
  spinner.increment_done!
39
-
39
+
40
40
  spinner.banner('wake up!')
41
41
  sleep 1
42
42
  spinner.increment_done!
43
43
  end
44
-
44
+
45
45
  Zzzz \ 3 of 3 [wake up!]
46
46
 
47
+ ## Threads
48
+
49
+ Spin to Win is built using [Celluloid](https://github.com/celluloid/celluloid) and was designed to be used by multiple threads.
50
+
51
+ SpinToWin.with_spinner('Dreaming about:') do |spinner|
52
+ futures = [
53
+ Celluloid::Future.new do
54
+ SpinToWin.add_banner('ham')
55
+ sleep 1
56
+ SpinToWin.increment_done!
57
+ SpinToWin.remove_banner('ham')
58
+ end,
59
+ Celluloid::Future.new do
60
+ SpinToWin.add_banner('sheep')
61
+ sleep 2
62
+ SpinToWin.increment_done!
63
+ SpinToWin.remove_banner('sheep')
64
+ end,
65
+ Celluloid::Future.new do
66
+ SpinToWin.add_banner('socks')
67
+ sleep 3
68
+ SpinToWin.increment_done!
69
+ SpinToWin.remove_banner('sock')
70
+ end
71
+ ]
72
+ SpinToWin.increment_todo!(futures.size)
73
+
74
+ futures.each { |f| f.value }
75
+ end
76
+
77
+ Dreaming about: \ 0 of 3 [ham|sheep|socks]
78
+
47
79
  ## Installation
48
80
 
49
81
  Add this line to your application's Gemfile:
@@ -61,7 +93,7 @@ Or install it yourself as:
61
93
  $ gem install spin_to_win
62
94
 
63
95
  ## Usage
64
-
96
+
65
97
  Fancy Demo \ 1 of 3 [step 1]
66
98
 
67
99
  ## Development
@@ -5,12 +5,12 @@ require 'spin_to_win/spinner'
5
5
  # Spinner
6
6
  module SpinToWin
7
7
  class << self
8
- def increment_todo!
9
- Celluloid::Notifications.notifier.publish('spinner_increment_todo')
8
+ def increment_todo!(count = 1)
9
+ Celluloid::Notifications.notifier.publish('spinner_increment_todo', count)
10
10
  end
11
11
 
12
- def increment_done!
13
- Celluloid::Notifications.notifier.publish('spinner_increment_done')
12
+ def increment_done!(count = 1)
13
+ Celluloid::Notifications.notifier.publish('spinner_increment_done', count)
14
14
  end
15
15
 
16
16
  def complete!
@@ -25,6 +25,10 @@ module SpinToWin
25
25
  Celluloid::Notifications.notifier.publish('spinner_set_banner', msg)
26
26
  end
27
27
 
28
+ def add_banner(msg)
29
+ Celluloid::Notifications.notifier.publish('spinner_add_banner', msg)
30
+ end
31
+
28
32
  def remove_banner(msg)
29
33
  Celluloid::Notifications.notifier.publish('spinner_remove_banner', msg)
30
34
  end
@@ -93,14 +93,12 @@ module SpinToWin
93
93
  @banner_queue = [banner]
94
94
  end
95
95
 
96
- private
97
-
98
- def on_increment_todo(*_args)
99
- increment_todo!
96
+ def on_increment_todo(*args)
97
+ increment_todo!(args[1] || 1)
100
98
  end
101
99
 
102
- def on_increment_done(*_args)
103
- increment_done!
100
+ def on_increment_done(*args)
101
+ increment_done!(args[1] || 1)
104
102
  end
105
103
 
106
104
  def on_output(*args)
@@ -123,6 +121,8 @@ module SpinToWin
123
121
  complete!
124
122
  end
125
123
 
124
+ private
125
+
126
126
  def init_spinner
127
127
  @run = true
128
128
  @todo_count = @done_count = 0
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module SpinToWin
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.1.2'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spin_to_win
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Guymon