rubikon 0.2.0 → 0.2.1
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.
- data/LICENSE +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/VERSION.yml +2 -3
- data/lib/rubikon.rb +0 -0
- data/lib/rubikon/action.rb +0 -0
- data/lib/rubikon/application/base.rb +0 -0
- data/lib/rubikon/application/class_methods.rb +0 -0
- data/lib/rubikon/application/instance_methods.rb +0 -0
- data/lib/rubikon/exceptions.rb +0 -0
- data/lib/rubikon/progress_bar.rb +12 -9
- data/lib/rubikon/throbber.rb +0 -0
- data/test/action_tests.rb +5 -5
- data/test/application_tests.rb +8 -8
- data/test/progress_bar_tests.rb +13 -13
- data/test/test_helper.rb +0 -0
- data/test/testapp.rb +1 -1
- data/test/throbber_tests.rb +8 -3
- metadata +3 -4
- data/lib/rubikon/setter.rb +0 -17
data/LICENSE
CHANGED
File without changes
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/VERSION.yml
CHANGED
data/lib/rubikon.rb
CHANGED
File without changes
|
data/lib/rubikon/action.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/rubikon/exceptions.rb
CHANGED
File without changes
|
data/lib/rubikon/progress_bar.rb
CHANGED
@@ -29,9 +29,10 @@ module Rubikon
|
|
29
29
|
@maximum.round
|
30
30
|
|
31
31
|
@progress_char = options[:char] || '#'
|
32
|
-
@factor = (options[:size] || 20).round.to_f / @maximum
|
33
32
|
@ostream = options[:ostream] || $stdout
|
34
33
|
@progress = 0
|
34
|
+
@size = options[:size] || 20
|
35
|
+
@factor = @size.round.to_f / @maximum
|
35
36
|
@value = 0
|
36
37
|
|
37
38
|
self + (options[:start] || 0)
|
@@ -48,19 +49,21 @@ module Rubikon
|
|
48
49
|
# progress_bar + 5 # (will add 5)
|
49
50
|
# progress_bar.+ # (will add 1)
|
50
51
|
def +(value = 1)
|
51
|
-
return if value <= 0
|
52
|
-
value = value.round
|
53
|
-
old_progress = @progress
|
52
|
+
return if (value <= 0) || (@value == @maximum)
|
54
53
|
@value += value
|
55
|
-
|
54
|
+
old_progress = @progress
|
55
|
+
add_progress = ((@value - @progress / @factor) * @factor).round
|
56
56
|
@progress += add_progress
|
57
57
|
|
58
|
-
|
58
|
+
if @progress > @size
|
59
|
+
@progress = @size
|
60
|
+
add_progress = @size - old_progress
|
61
|
+
end
|
59
62
|
|
60
|
-
|
61
|
-
|
62
|
-
@ostream << @progress_char * difference
|
63
|
+
if add_progress > 0
|
64
|
+
@ostream << @progress_char * add_progress
|
63
65
|
@ostream.flush
|
66
|
+
@ostream.puts '' if @progress == @size
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
data/lib/rubikon/throbber.rb
CHANGED
File without changes
|
data/test/action_tests.rb
CHANGED
@@ -10,12 +10,12 @@ class ActionTests < Test::Unit::TestCase
|
|
10
10
|
context 'A Rubikon action' do
|
11
11
|
|
12
12
|
should 'throw an exception when no code block is given' do
|
13
|
-
assert_raise
|
14
|
-
|
13
|
+
assert_raise BlockMissingError do
|
14
|
+
Action.new
|
15
15
|
end
|
16
|
-
assert_raise
|
16
|
+
assert_raise BlockMissingError do
|
17
17
|
options = {}
|
18
|
-
|
18
|
+
Action.new options
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -25,7 +25,7 @@ class ActionTests < Test::Unit::TestCase
|
|
25
25
|
:param_type => String
|
26
26
|
}
|
27
27
|
assert_nothing_raised do
|
28
|
-
action =
|
28
|
+
action = Action.new action_options do end
|
29
29
|
assert_equal action_options[:description], action.description
|
30
30
|
assert_equal action_options[:param_type], action.param_type
|
31
31
|
end
|
data/test/application_tests.rb
CHANGED
@@ -61,26 +61,26 @@ class ApplicationTests < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
should 'not run without a mandatory argument' do
|
64
|
-
assert_raise
|
64
|
+
assert_raise MissingArgumentError do
|
65
65
|
@app.run(%w{--required})
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
should 'require an argument type if it has been defined' do
|
70
|
-
assert_raise
|
70
|
+
assert_raise ArgumentTypeError do
|
71
71
|
@app.run(['--output', 6])
|
72
72
|
end
|
73
|
-
assert_raise
|
73
|
+
assert_raise ArgumentTypeError do
|
74
74
|
@app.run(['--number_string', 6, 7])
|
75
75
|
end
|
76
|
-
assert_raise
|
76
|
+
assert_raise ArgumentTypeError do
|
77
77
|
@app.run(['--number_string', 'test' , 6])
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
should 'raise an exception when calling an action with the wrong number of
|
82
82
|
arguments' do
|
83
|
-
assert_raise
|
83
|
+
assert_raise MissingArgumentError do
|
84
84
|
@app.run(%w{--output})
|
85
85
|
end
|
86
86
|
assert_raise ArgumentError do
|
@@ -89,13 +89,13 @@ class ApplicationTests < Test::Unit::TestCase
|
|
89
89
|
end
|
90
90
|
|
91
91
|
should 'raise an exception when using an unknown option' do
|
92
|
-
assert_raise
|
92
|
+
assert_raise UnknownOptionError do
|
93
93
|
@app.run(%w{--unknown})
|
94
94
|
end
|
95
|
-
assert_raise
|
95
|
+
assert_raise UnknownOptionError do
|
96
96
|
@app.run(%w{--noarg --unknown})
|
97
97
|
end
|
98
|
-
assert_raise
|
98
|
+
assert_raise UnknownOptionError do
|
99
99
|
@app.run(%w{--unknown --noarg})
|
100
100
|
end
|
101
101
|
end
|
data/test/progress_bar_tests.rb
CHANGED
@@ -10,7 +10,7 @@ class ProgressBarTests < Test::Unit::TestCase
|
|
10
10
|
context 'A progress bar' do
|
11
11
|
|
12
12
|
should 'have default settings' do
|
13
|
-
@bar =
|
13
|
+
@bar = ProgressBar.new
|
14
14
|
assert_equal 0.2, @bar.instance_variable_get(:@factor)
|
15
15
|
assert_equal 100, @bar.instance_variable_get(:@maximum)
|
16
16
|
assert_equal $stdout, @bar.instance_variable_get(:@ostream)
|
@@ -27,7 +27,7 @@ class ProgressBarTests < Test::Unit::TestCase
|
|
27
27
|
:size => 100,
|
28
28
|
:start => 5
|
29
29
|
}
|
30
|
-
@bar =
|
30
|
+
@bar = ProgressBar.new(options)
|
31
31
|
assert_equal options[:size].to_f / options[:maximum], @bar.instance_variable_get(:@factor)
|
32
32
|
assert_equal options[:maximum], @bar.instance_variable_get(:@maximum)
|
33
33
|
assert_equal options[:ostream], @bar.instance_variable_get(:@ostream)
|
@@ -40,15 +40,15 @@ class ProgressBarTests < Test::Unit::TestCase
|
|
40
40
|
ostream = StringIO.new
|
41
41
|
options = { :ostream => ostream, :start => 50 }
|
42
42
|
|
43
|
-
@bar =
|
43
|
+
@bar = ProgressBar.new(options)
|
44
44
|
assert_equal "#" * 10, ostream.string
|
45
45
|
@bar + 50
|
46
|
-
assert_equal "#" * 20, ostream.string
|
46
|
+
assert_equal ("#" * 20) << "\n", ostream.string
|
47
47
|
|
48
48
|
ostream.string = ''
|
49
49
|
options[:size] = 10
|
50
50
|
|
51
|
-
@bar =
|
51
|
+
@bar = ProgressBar.new(options)
|
52
52
|
assert_equal "#" * 5, ostream.string
|
53
53
|
@bar + 10
|
54
54
|
assert_equal "#" * 6, ostream.string
|
@@ -56,7 +56,7 @@ class ProgressBarTests < Test::Unit::TestCase
|
|
56
56
|
ostream.string = ''
|
57
57
|
options[:size] = 100
|
58
58
|
|
59
|
-
@bar =
|
59
|
+
@bar = ProgressBar.new(options)
|
60
60
|
assert_equal "#" * 50, ostream.string
|
61
61
|
@bar + 30
|
62
62
|
assert_equal "#" * 80, ostream.string
|
@@ -66,26 +66,26 @@ class ProgressBarTests < Test::Unit::TestCase
|
|
66
66
|
ostream = StringIO.new
|
67
67
|
options = { :ostream => ostream, :size => 100 }
|
68
68
|
|
69
|
-
@bar =
|
69
|
+
@bar = ProgressBar.new options
|
70
70
|
@bar + 101
|
71
|
-
assert_equal "#" * 100, ostream.string
|
71
|
+
assert_equal ("#" * 100) << "\n", ostream.string
|
72
72
|
assert_equal 100, @bar.instance_variable_get(:@progress)
|
73
73
|
assert_equal 101, @bar.instance_variable_get(:@value)
|
74
74
|
|
75
75
|
ostream.string = ''
|
76
76
|
options[:start] = 50
|
77
77
|
|
78
|
-
@bar =
|
78
|
+
@bar = ProgressBar.new options
|
79
79
|
@bar + 51
|
80
|
-
assert_equal "#" * 100, ostream.string
|
80
|
+
assert_equal ("#" * 100) << "\n", ostream.string
|
81
81
|
assert_equal 100, @bar.instance_variable_get(:@progress)
|
82
82
|
assert_equal 101, @bar.instance_variable_get(:@value)
|
83
83
|
|
84
84
|
ostream.string = ''
|
85
85
|
options[:start] = 101
|
86
|
-
|
87
|
-
@bar =
|
88
|
-
assert_equal "#" * 100, ostream.string
|
86
|
+
|
87
|
+
@bar = ProgressBar.new options
|
88
|
+
assert_equal ("#" * 100) << "\n", ostream.string
|
89
89
|
assert_equal 100, @bar.instance_variable_get(:@progress)
|
90
90
|
assert_equal 101, @bar.instance_variable_get(:@value)
|
91
91
|
end
|
data/test/test_helper.rb
CHANGED
File without changes
|
data/test/testapp.rb
CHANGED
data/test/throbber_tests.rb
CHANGED
@@ -10,12 +10,17 @@ class ThrobberTests < Test::Unit::TestCase
|
|
10
10
|
context 'A throbber' do
|
11
11
|
|
12
12
|
should 'be a subclass of Thread' do
|
13
|
-
assert_equal Thread,
|
13
|
+
assert_equal Thread, Throbber.superclass
|
14
14
|
end
|
15
15
|
|
16
16
|
should 'have default throbber strings' do
|
17
|
-
|
18
|
-
|
17
|
+
unless RUBY_VERSION[0..2] == '1.9'
|
18
|
+
consts = %w{SPINNER}
|
19
|
+
else
|
20
|
+
consts = [:SPINNER, :MUTEX_FOR_THREAD_EXCLUSIVE]
|
21
|
+
end
|
22
|
+
assert_equal consts, Throbber.constants
|
23
|
+
assert_equal '-\|/', Throbber.const_get(:SPINNER)
|
19
24
|
end
|
20
25
|
|
21
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubikon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Staudt
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-09 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,7 +34,6 @@ files:
|
|
34
34
|
- lib/rubikon/application/instance_methods.rb
|
35
35
|
- lib/rubikon/exceptions.rb
|
36
36
|
- lib/rubikon/progress_bar.rb
|
37
|
-
- lib/rubikon/setter.rb
|
38
37
|
- lib/rubikon/throbber.rb
|
39
38
|
- test/action_tests.rb
|
40
39
|
- test/application_tests.rb
|
@@ -78,6 +77,6 @@ test_files:
|
|
78
77
|
- test/action_tests.rb
|
79
78
|
- test/application_tests.rb
|
80
79
|
- test/progress_bar_tests.rb
|
81
|
-
- test/test_helper.rb
|
82
80
|
- test/testapp.rb
|
81
|
+
- test/test_helper.rb
|
83
82
|
- test/throbber_tests.rb
|
data/lib/rubikon/setter.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under the
|
2
|
-
# terms of the new BSD License.
|
3
|
-
#
|
4
|
-
# Copyright (c) 2009, Sebastian Staudt
|
5
|
-
|
6
|
-
module Rubikon
|
7
|
-
|
8
|
-
class Setter < Action
|
9
|
-
|
10
|
-
def run(*args)
|
11
|
-
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|