rib 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.gitmodules +3 -0
- data/.travis.yml +9 -0
- data/2011-02-28.md +203 -0
- data/CHANGES +86 -0
- data/CONTRIBUTORS +2 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README +190 -0
- data/README.md +190 -0
- data/Rakefile +20 -0
- data/TODO +6 -0
- data/lib/rib.rb +42 -0
- data/lib/rib/all.rb +4 -0
- data/lib/rib/api.rb +105 -0
- data/lib/rib/core.rb +5 -0
- data/lib/rib/core/completion.rb +22 -0
- data/lib/rib/core/history_file.rb +38 -0
- data/lib/rib/core/readline.rb +19 -0
- data/lib/rib/core/underscore.rb +53 -0
- data/lib/rib/debug.rb +3 -0
- data/lib/rib/more.rb +12 -0
- data/lib/rib/more/color.rb +98 -0
- data/lib/rib/more/multiline.rb +77 -0
- data/lib/rib/more/multiline_history.rb +31 -0
- data/lib/rib/more/multiline_history_file.rb +37 -0
- data/lib/rib/more/squeeze_history.rb +37 -0
- data/lib/rib/more/strip_backtrace.rb +43 -0
- data/lib/rib/plugin.rb +56 -0
- data/lib/rib/runner.rb +106 -0
- data/lib/rib/shell.rb +43 -0
- data/lib/rib/test.rb +25 -0
- data/lib/rib/version.rb +4 -0
- data/lib/rib/zore.rb +3 -0
- data/lib/rib/zore/anchor.rb +69 -0
- data/lib/rib/zore/edit.rb +33 -0
- data/rib.gemspec +104 -0
- data/screenshot.png +0 -0
- data/task/.gitignore +1 -0
- data/task/gemgem.rb +182 -0
- data/test/core/test_completion.rb +18 -0
- data/test/core/test_history_file.rb +57 -0
- data/test/core/test_readline.rb +21 -0
- data/test/core/test_underscore.rb +41 -0
- data/test/more/test_color.rb +28 -0
- data/test/more/test_squeeze_history.rb +43 -0
- data/test/test_api.rb +20 -0
- data/test/test_plugin.rb +38 -0
- data/test/test_shell.rb +82 -0
- metadata +77 -13
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
require 'rib/test'
|
3
|
+
require 'rib/more/color'
|
4
|
+
|
5
|
+
describe Rib::Color do
|
6
|
+
behaves_like :rib
|
7
|
+
|
8
|
+
before do
|
9
|
+
@color = Class.new do
|
10
|
+
include Rib::Color
|
11
|
+
def colors
|
12
|
+
@colors ||= Rib::Shell.new.before_loop.config[:color]
|
13
|
+
end
|
14
|
+
end.new
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'give correct color' do
|
18
|
+
@color.send(:format_color,
|
19
|
+
[{0 => :a}, 'b', [nil, {false => Object}], {true => Exception.new}]).
|
20
|
+
should.eq \
|
21
|
+
"\e[34m[\e[m\e[34m{\e[m\e[31m0\e[m\e[34m=>\e[m\e[36m:a\e[m\e[" \
|
22
|
+
"34m}\e[m\e[34m, \e[m\e[32m\"b\"\e[m\e[34m, \e[m\e[34m[\e[m\e" \
|
23
|
+
"[35mnil\e[m\e[34m, \e[m\e[34m{\e[m\e[35mfalse\e[m\e[34m=>\e[" \
|
24
|
+
"m\e[33mObject\e[m\e[34m}\e[m\e[34m]\e[m\e[34m, \e[m\e[34m{\e" \
|
25
|
+
"[m\e[35mtrue\e[m\e[34m=>\e[m\e[35m#<Exception: Exception>\e[" \
|
26
|
+
"m\e[34m}\e[m\e[34m]\e[m"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
require 'rib/test'
|
3
|
+
require 'rib/more/squeeze_history'
|
4
|
+
|
5
|
+
describe Rib::SqueezeHistory do
|
6
|
+
behaves_like :rib
|
7
|
+
|
8
|
+
before do
|
9
|
+
Rib::HistoryFile.enable
|
10
|
+
Rib::SqueezeHistory.enable
|
11
|
+
@history = "/tmp/test_rib_#{rand}"
|
12
|
+
@shell = Rib::Shell.new(:history_file => @history).before_loop
|
13
|
+
@input = %w[foo bar bar foo bar]
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
FileUtils.rm_f(@history)
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'after_loop saves squeezed history' do
|
21
|
+
@shell.history.push(*@input)
|
22
|
+
@shell.after_loop
|
23
|
+
File.read(@history).should.eq %w[foo bar foo bar].join("\n") + "\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'loop_once squeeze history' do
|
27
|
+
times = @input.size
|
28
|
+
stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'")[-1] }
|
29
|
+
stub(@shell).print_result(anything)
|
30
|
+
times.times{ @shell.loop_once }
|
31
|
+
@shell.history.to_a.should.eq %w[foo bar foo bar].map{ |i| "'#{i}'" }
|
32
|
+
end
|
33
|
+
|
34
|
+
should 'be disabled if disabled' do
|
35
|
+
Rib::SqueezeHistory.disable
|
36
|
+
times = @input.size
|
37
|
+
input = @input.dup
|
38
|
+
stub(@shell).get_input{ (@shell.history << "'#{@input.shift}'")[-1] }
|
39
|
+
stub(@shell).print_result(anything)
|
40
|
+
times.times{ @shell.loop_once }
|
41
|
+
@shell.history.to_a.should.eq input.map{ |i| "'#{i}'" }
|
42
|
+
end
|
43
|
+
end
|
data/test/test_api.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'rib/test'
|
3
|
+
require 'rib/shell'
|
4
|
+
|
5
|
+
describe Rib::API do
|
6
|
+
behaves_like :rib
|
7
|
+
|
8
|
+
Rib::API.instance_methods.delete_if{ |e| e[/=$/] }.each do |meth|
|
9
|
+
should "##{meth} be accessible to plugins" do
|
10
|
+
mod = Module.new do
|
11
|
+
define_method meth do
|
12
|
+
"pong_#{meth}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
shell = Rib::Shell.dup
|
16
|
+
shell.use(mod)
|
17
|
+
shell.new.send(meth).should == "pong_#{meth}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/test/test_plugin.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require 'rib/test'
|
3
|
+
require 'rib/all'
|
4
|
+
|
5
|
+
describe Rib::Plugin do
|
6
|
+
behaves_like :rib
|
7
|
+
|
8
|
+
before do
|
9
|
+
@names = Dir[File.expand_path(
|
10
|
+
"#{File.dirname(__FILE__)}/../lib/rib/{core,more,zore}/*.rb")].
|
11
|
+
map {|path| File.basename(path)[0..-4] }
|
12
|
+
@mods = Rib.plugins
|
13
|
+
end
|
14
|
+
|
15
|
+
should 'have shortcut methods' do
|
16
|
+
@names.each{ |name|
|
17
|
+
%w[enable disable].each{ |meth|
|
18
|
+
Rib.respond_to?("#{meth}_#{name}").should == true
|
19
|
+
}
|
20
|
+
%w[enabled? disabled?].each{ |meth|
|
21
|
+
Rib.respond_to?("#{name}_#{meth}").should == true
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'be the same as mod methods' do
|
27
|
+
@mods.shuffle.take(@mods.size/2).each(&:disable)
|
28
|
+
@names.each{ |name|
|
29
|
+
%w[enabled? disabled?].each{ |meth|
|
30
|
+
Rib.send("#{name}_#{meth}").should ==
|
31
|
+
@mods.find{ |mod|
|
32
|
+
mod.name[/::\w+$/].tr(':', '') ==
|
33
|
+
name.gsub(/([^_]+)/){$1.capitalize}.tr('_', '') }.
|
34
|
+
send(meth)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
data/test/test_shell.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
require 'rib/test'
|
3
|
+
require 'rib/shell'
|
4
|
+
|
5
|
+
describe Rib::Shell do
|
6
|
+
behaves_like :rib
|
7
|
+
|
8
|
+
before do
|
9
|
+
@shell = Rib::Shell.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#loop' do
|
13
|
+
def input str
|
14
|
+
mock(@shell).get_input{str}
|
15
|
+
@shell.loop.should.eq @shell
|
16
|
+
end
|
17
|
+
should 'exit' do input('exit') end
|
18
|
+
should 'quit' do input('quit') end
|
19
|
+
should 'ctrl+d' do mock(@shell).puts; input(nil) end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#loop_once' do
|
23
|
+
def input str=nil
|
24
|
+
if block_given?
|
25
|
+
mock(@shell).get_input{ yield }
|
26
|
+
else
|
27
|
+
mock(@shell).get_input{ str }
|
28
|
+
end
|
29
|
+
@shell.loop_once.should.eq nil
|
30
|
+
end
|
31
|
+
|
32
|
+
should 'handles ctrl+c' do
|
33
|
+
mock(@shell).handle_interrupt
|
34
|
+
input{ raise Interrupt }
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'prints result' do
|
38
|
+
mock(@shell).puts('=> "mm"')
|
39
|
+
input('"m" * 2')
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'error in print_result' do
|
43
|
+
mock(@shell).warn(/rib: Error while printing result.*BOOM/m)
|
44
|
+
input('obj = Object.new; def obj.inspect; raise "BOOM"; end; obj')
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'print error from eval' do
|
48
|
+
mock(@shell).warn(/RuntimeError/)
|
49
|
+
input('raise "blah"')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#prompt' do
|
54
|
+
should 'be changeable' do
|
55
|
+
@shell.config[:prompt] = '> '
|
56
|
+
@shell.prompt.should.eq '> '
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#eval_input' do
|
61
|
+
before do
|
62
|
+
@line = @shell.config[:line]
|
63
|
+
end
|
64
|
+
|
65
|
+
should 'line' do
|
66
|
+
@shell.eval_input('10 ** 2')
|
67
|
+
@shell.config[:line].should.eq @line + 1
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'print error and increments line' do
|
71
|
+
mock(@shell).warn(/^SyntaxError:/)
|
72
|
+
@shell.eval_input('{').should.eq nil
|
73
|
+
@shell.config[:line] .should.eq @line + 1
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'call after_loop even if in_loop raises' do
|
78
|
+
mock(@shell).loop_once{ raise 'boom' }
|
79
|
+
mock(@shell).after_loop
|
80
|
+
lambda{ @shell.loop }.should.raise(RuntimeError)
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bond
|
16
|
-
requirement: &
|
16
|
+
requirement: &2157065040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2157065040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bacon
|
27
|
-
requirement: &
|
27
|
+
requirement: &2157064560 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2157064560
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rr
|
38
|
-
requirement: &
|
38
|
+
requirement: &2157064080 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,20 +43,75 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
description:
|
46
|
+
version_requirements: *2157064080
|
47
|
+
description: ripl plugins collection, take you want, leave you don't.
|
48
48
|
email:
|
49
49
|
- godfat (XD) godfat.org
|
50
50
|
executables:
|
51
51
|
- rib
|
52
52
|
extensions: []
|
53
|
-
extra_rdoc_files:
|
53
|
+
extra_rdoc_files:
|
54
|
+
- CHANGES
|
55
|
+
- CONTRIBUTORS
|
56
|
+
- LICENSE
|
57
|
+
- TODO
|
54
58
|
files:
|
59
|
+
- .gitignore
|
60
|
+
- .gitmodules
|
61
|
+
- .travis.yml
|
62
|
+
- 2011-02-28.md
|
63
|
+
- CHANGES
|
64
|
+
- CONTRIBUTORS
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- TODO
|
55
71
|
- bin/rib
|
72
|
+
- lib/rib.rb
|
73
|
+
- lib/rib/all.rb
|
74
|
+
- lib/rib/api.rb
|
75
|
+
- lib/rib/core.rb
|
76
|
+
- lib/rib/core/completion.rb
|
77
|
+
- lib/rib/core/history_file.rb
|
78
|
+
- lib/rib/core/readline.rb
|
79
|
+
- lib/rib/core/underscore.rb
|
80
|
+
- lib/rib/debug.rb
|
81
|
+
- lib/rib/more.rb
|
82
|
+
- lib/rib/more/color.rb
|
83
|
+
- lib/rib/more/multiline.rb
|
84
|
+
- lib/rib/more/multiline_history.rb
|
85
|
+
- lib/rib/more/multiline_history_file.rb
|
86
|
+
- lib/rib/more/squeeze_history.rb
|
87
|
+
- lib/rib/more/strip_backtrace.rb
|
88
|
+
- lib/rib/plugin.rb
|
89
|
+
- lib/rib/runner.rb
|
90
|
+
- lib/rib/shell.rb
|
91
|
+
- lib/rib/test.rb
|
92
|
+
- lib/rib/version.rb
|
93
|
+
- lib/rib/zore.rb
|
94
|
+
- lib/rib/zore/anchor.rb
|
95
|
+
- lib/rib/zore/edit.rb
|
96
|
+
- rib.gemspec
|
97
|
+
- screenshot.png
|
98
|
+
- task/.gitignore
|
99
|
+
- task/gemgem.rb
|
100
|
+
- test/core/test_completion.rb
|
101
|
+
- test/core/test_history_file.rb
|
102
|
+
- test/core/test_readline.rb
|
103
|
+
- test/core/test_underscore.rb
|
104
|
+
- test/more/test_color.rb
|
105
|
+
- test/more/test_squeeze_history.rb
|
106
|
+
- test/test_api.rb
|
107
|
+
- test/test_plugin.rb
|
108
|
+
- test/test_shell.rb
|
56
109
|
homepage: https://github.com/godfat/rib
|
57
110
|
licenses: []
|
58
111
|
post_install_message:
|
59
|
-
rdoc_options:
|
112
|
+
rdoc_options:
|
113
|
+
- --main
|
114
|
+
- README
|
60
115
|
require_paths:
|
61
116
|
- lib
|
62
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -76,5 +131,14 @@ rubyforge_project:
|
|
76
131
|
rubygems_version: 1.8.7
|
77
132
|
signing_key:
|
78
133
|
specification_version: 3
|
79
|
-
summary:
|
80
|
-
test_files:
|
134
|
+
summary: ripl plugins collection, take you want, leave you don't.
|
135
|
+
test_files:
|
136
|
+
- test/core/test_completion.rb
|
137
|
+
- test/core/test_history_file.rb
|
138
|
+
- test/core/test_readline.rb
|
139
|
+
- test/core/test_underscore.rb
|
140
|
+
- test/more/test_color.rb
|
141
|
+
- test/more/test_squeeze_history.rb
|
142
|
+
- test/test_api.rb
|
143
|
+
- test/test_plugin.rb
|
144
|
+
- test/test_shell.rb
|