ripl 0.2.4 → 0.2.5
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/.gemspec +1 -1
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +5 -3
- data/lib/ripl/history.rb +1 -1
- data/lib/ripl/runner.rb +27 -20
- data/lib/ripl/shell.rb +5 -0
- data/lib/ripl/version.rb +1 -1
- data/test/deps.rip +1 -1
- data/test/runner_test.rb +25 -12
- data/test/shell_test.rb +10 -2
- data/test/test_helper.rb +10 -2
- metadata +9 -9
data/.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.executables = %w(ripl)
|
16
16
|
s.add_dependency 'bond', '~> 0.3.3'
|
17
17
|
s.add_development_dependency 'bacon', '>= 1.1.0'
|
18
|
-
s.add_development_dependency 'rr', '
|
18
|
+
s.add_development_dependency 'rr', '>= 1.0.0'
|
19
19
|
s.add_development_dependency 'bacon-bits'
|
20
20
|
s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
|
21
21
|
s.files += Dir.glob('man/*')
|
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -61,7 +61,7 @@ modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:
|
|
61
61
|
* 6 common commandline options: -f, -r, -I, -d, -h, -v
|
62
62
|
* IRB.conf -> Ripl.config
|
63
63
|
* Enhancements over irb
|
64
|
-
* ~
|
64
|
+
* ~250 lines (doc included) vs irb's 5000+ lines
|
65
65
|
* Easily extendable with plugins
|
66
66
|
* Tests and documentation!
|
67
67
|
* Customizable completion and completion of method arguments (from bond)
|
@@ -78,7 +78,7 @@ Note: Irb features not in ripl can be implemented as plugins.
|
|
78
78
|
|
79
79
|
== Plugins
|
80
80
|
|
81
|
-
A ripl plugin is a module that is included into Ripl::Shell or Ripl::Runner. Being simply modules,
|
81
|
+
A ripl plugin is a module that is included into Ripl::Shell or extended into Ripl::Runner. Being simply modules,
|
82
82
|
they can be packaged as gems and reused across shells as needed. ripl highly encourages plugins by
|
83
83
|
loading them as early as possible and allowing them to extend most of ripl's functionality.
|
84
84
|
|
@@ -136,9 +136,11 @@ see {ripl-rails}[http://github.com/cldwalker/ripl-rails].
|
|
136
136
|
|
137
137
|
* {ripl-rails}[http://github.com/cldwalker/ripl-rails] : script/console for ripl
|
138
138
|
* {ripl-color_error}[http://github.com/cldwalker/ripl-color_error] : colorize errors
|
139
|
-
* {ripl-after_rc}[http://github.com/cldwalker/ripl-after_rc] : provide blocks to run after ~/.irbrc is loaded
|
140
139
|
* {ripl-multi_line}[http://github.com/janlelis/ripl-multi_line] : evaluate multiple lines
|
140
|
+
* {ripl-after_rc}[http://github.com/cldwalker/ripl-after_rc] : provide blocks to run after ~/.irbrc is loaded
|
141
141
|
* {ripl-irb}[http://github.com/cldwalker/ripl-irb] : smooths transition from irb
|
142
|
+
* {ripl-commands}[http://github.com/cldwalker/ripl-commands] : adds ripl commands similar to irb's commands
|
143
|
+
* {ripl-color_streams}[http://github.com/janlelis/ripl-color_streams] : colorizes stderr + stdout
|
142
144
|
* {ripl-color_result}[http://github.com/janlelis/ripl-color_result] : colorizes results
|
143
145
|
* {nirvana}[http://github.com/cldwalker/nirvana]: Not a plugin but rather a web shell built on top of ripl
|
144
146
|
|
data/lib/ripl/history.rb
CHANGED
data/lib/ripl/runner.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
module Ripl::Runner
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
OPTIONS = [
|
3
|
+
['-f', 'Suppress loading ~/.irbrc'],
|
4
|
+
['-F', 'Suppress loading ~/.riplrc'],
|
5
|
+
['-d, --debug', "Set $DEBUG to true (same as `ruby -d')"],
|
6
|
+
['-I PATH', "Add to front of $LOAD_PATH. Delimit multiple paths with ':'"],
|
7
|
+
['-r, --require FILE', "Require file (same as `ruby -r')"],
|
8
|
+
['-v, --version', 'Print ripl version'],
|
9
|
+
['-h, --help', 'Print help']
|
10
|
+
]
|
5
11
|
|
6
12
|
module API
|
13
|
+
def options; OPTIONS; end
|
14
|
+
|
7
15
|
def run(argv=ARGV)
|
8
|
-
|
9
|
-
|
16
|
+
ENV['RIPLRC'] = 'false' if argv.delete('-F')
|
17
|
+
load_rc(Ripl.config[:riplrc]) unless ENV['RIPLRC'] == 'false'
|
18
|
+
@run = true
|
10
19
|
parse_options(argv)
|
11
20
|
argv[0] ? run_command(argv) : start
|
12
21
|
end
|
@@ -25,13 +34,21 @@ module Ripl::Runner
|
|
25
34
|
when '-f'
|
26
35
|
ENV['RIPL_IRBRC'] = 'false'
|
27
36
|
when '-h', '--help'
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
name_max = options.map {|e| e[0].length }.max
|
38
|
+
desc_max = options.map {|e| e[1].length }.max
|
39
|
+
puts "Usage: ripl [OPTIONS] [COMMAND] [ARGS]", "\nOptions:",
|
40
|
+
options.map {|k,v| " %-*s %-*s" % [name_max, k, desc_max, v] }
|
41
|
+
exit
|
42
|
+
when /^(--?[^-]+)/
|
43
|
+
invalid_option($1, argv)
|
31
44
|
end
|
32
45
|
end
|
33
46
|
end
|
34
47
|
|
48
|
+
def invalid_option(option, argv)
|
49
|
+
warn "ripl: invalid option `#{option.sub(/^-+/, '')}'"
|
50
|
+
end
|
51
|
+
|
35
52
|
def run_command(argv)
|
36
53
|
exec "ripl-#{argv.shift}", *argv
|
37
54
|
rescue Errno::ENOENT
|
@@ -40,7 +57,7 @@ module Ripl::Runner
|
|
40
57
|
end
|
41
58
|
|
42
59
|
def start(options={})
|
43
|
-
load_rc(Ripl.config[:riplrc])
|
60
|
+
load_rc(Ripl.config[:riplrc]) if !@run && ENV['RIPLRC'] != 'false'
|
44
61
|
Ripl.config[:irbrc] = ENV['RIPL_IRBRC'] != 'false' if ENV['RIPL_IRBRC']
|
45
62
|
Ripl.shell(options).loop
|
46
63
|
end
|
@@ -48,7 +65,7 @@ module Ripl::Runner
|
|
48
65
|
def load_rc(file)
|
49
66
|
load file if File.exists?(File.expand_path(file))
|
50
67
|
rescue StandardError, SyntaxError
|
51
|
-
warn "Error while loading #{file}:\n"+ format_error($!)
|
68
|
+
warn "ripl: Error while loading #{file}:\n"+ format_error($!)
|
52
69
|
end
|
53
70
|
|
54
71
|
def format_error(err)
|
@@ -57,13 +74,3 @@ module Ripl::Runner
|
|
57
74
|
end
|
58
75
|
extend API
|
59
76
|
end
|
60
|
-
__END__
|
61
|
-
# Usage: ripl [OPTIONS] [COMMAND] [ARGS]
|
62
|
-
#
|
63
|
-
# Options:
|
64
|
-
# -f Supress loading ~/.irbrc
|
65
|
-
# -d, --debug Set $DEBUG to true (same as `ruby -d')
|
66
|
-
# -I PATH Add to front of $LOAD_PATH. Delimit multiple paths with ':'
|
67
|
-
# -r, --require FILE Require file (same as `ruby -r')
|
68
|
-
# -v, --version Print ripl version
|
69
|
-
# -h, --help Print help
|
data/lib/ripl/shell.rb
CHANGED
@@ -61,6 +61,8 @@ class Ripl::Shell
|
|
61
61
|
@line += 1
|
62
62
|
end
|
63
63
|
|
64
|
+
# When extending this method, ensure your plugin disables readline:
|
65
|
+
# Readline.config[:readline] = false.
|
64
66
|
# @return [String, nil] Prints #prompt and returns input given by user
|
65
67
|
def get_input
|
66
68
|
print prompt
|
@@ -70,6 +72,9 @@ class Ripl::Shell
|
|
70
72
|
# @return [String]
|
71
73
|
def prompt
|
72
74
|
@prompt.respond_to?(:call) ? @prompt.call : @prompt
|
75
|
+
rescue StandardError, SyntaxError
|
76
|
+
warn "ripl: Error while creating prompt:\n"+ format_error($!)
|
77
|
+
OPTIONS[:prompt]
|
73
78
|
end
|
74
79
|
|
75
80
|
# Evals user input using @binding, @name and @line
|
data/lib/ripl/version.rb
CHANGED
data/test/deps.rip
CHANGED
data/test/runner_test.rb
CHANGED
@@ -6,20 +6,20 @@ describe "Runner" do
|
|
6
6
|
|
7
7
|
it "loads riplrc" do
|
8
8
|
mock_riplrc
|
9
|
-
|
9
|
+
mock_shell
|
10
10
|
Ripl.start
|
11
11
|
end
|
12
12
|
|
13
13
|
it "sets a shell's variables" do
|
14
14
|
mock_riplrc
|
15
|
-
|
15
|
+
mock_shell
|
16
16
|
Ripl.start(:name=>'shh')
|
17
17
|
Ripl.shell.name.should == 'shh'
|
18
18
|
end
|
19
19
|
|
20
20
|
it "overrides config set in riplrc" do
|
21
21
|
mock_riplrc { Ripl.config[:name] = 'blah' }
|
22
|
-
|
22
|
+
mock_shell
|
23
23
|
Ripl.start(:name=>'dude')
|
24
24
|
Ripl.shell.name.should == 'dude'
|
25
25
|
end
|
@@ -31,15 +31,15 @@ describe "Runner" do
|
|
31
31
|
|
32
32
|
it "sets config" do
|
33
33
|
mock_riplrc { Ripl.config[:blah] = true }
|
34
|
-
|
34
|
+
mock_shell
|
35
35
|
Runner.run([])
|
36
36
|
Ripl.config[:blah].should == true
|
37
37
|
end
|
38
38
|
|
39
39
|
it "catches and prints error" do
|
40
40
|
mock(Runner).load(anything) { raise SyntaxError }
|
41
|
-
|
42
|
-
capture_stderr { Runner.run([]) }.should =~ %r{^Error while loading ~/.riplrc:\nSyntaxError:}
|
41
|
+
mock_shell
|
42
|
+
capture_stderr { Runner.run([]) }.should =~ %r{^ripl: Error while loading ~/.riplrc:\nSyntaxError:}
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -49,10 +49,11 @@ describe "Runner" do
|
|
49
49
|
ripl("rails", '--blah')
|
50
50
|
end
|
51
51
|
|
52
|
-
it "has global
|
53
|
-
mock(Runner).parse_options(anything) {|e| e.shift }
|
52
|
+
it "has global option before it parsed" do
|
54
53
|
mock(Runner).exec('ripl-rails')
|
55
|
-
|
54
|
+
dont_allow(Runner).load_rc(anything)
|
55
|
+
ripl("-F", "rails", :riplrc=>false)
|
56
|
+
ENV.delete('RIPLRC')
|
56
57
|
end
|
57
58
|
|
58
59
|
it "that is invalid aborts" do
|
@@ -127,16 +128,28 @@ describe "Runner" do
|
|
127
128
|
|
128
129
|
it "with -f option doesn't load irbrc" do
|
129
130
|
reset_ripl
|
130
|
-
|
131
|
-
|
131
|
+
stub(Kernel).at_exit()
|
132
|
+
mock_shell { |shell|
|
132
133
|
mock(shell).loop_once { throw :ripl_exit }
|
133
134
|
dont_allow(Runner).load_rc(anything)
|
134
|
-
shell
|
135
135
|
}
|
136
136
|
ripl("-f")
|
137
|
+
ENV.delete('RIPL_IRBRC')
|
137
138
|
Ripl.config[:irbrc] = '~/.irbrc'
|
138
139
|
end
|
139
140
|
|
141
|
+
it "with -F option doesn't load riplrc" do
|
142
|
+
reset_ripl
|
143
|
+
dont_allow(Runner).load_rc(anything)
|
144
|
+
mock_shell { |shell|
|
145
|
+
stub(Kernel).at_exit
|
146
|
+
mock(shell).before_loop
|
147
|
+
mock(shell).loop_once { throw :ripl_exit }
|
148
|
+
}
|
149
|
+
ripl("-F", :riplrc => false)
|
150
|
+
ENV.delete('RIPLRC')
|
151
|
+
end
|
152
|
+
|
140
153
|
it "with -d option sets $DEBUG" do
|
141
154
|
ripl("-d", :start=>true)
|
142
155
|
$DEBUG.should == true
|
data/test/shell_test.rb
CHANGED
@@ -23,19 +23,26 @@ describe "Shell" do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe "#prompt" do
|
26
|
-
it "
|
26
|
+
it "from a string" do
|
27
27
|
shell(:prompt=>'> ').prompt.should == '> '
|
28
28
|
end
|
29
29
|
|
30
|
-
it "
|
30
|
+
it "from a lambda" do
|
31
31
|
shell(:prompt=>lambda { "#{10 + 10}> " }).prompt.should == '20> '
|
32
32
|
end
|
33
|
+
|
34
|
+
it "rescues from a failed lambda" do
|
35
|
+
capture_stderr {
|
36
|
+
shell(:prompt=>lambda { wtf }).prompt.should == Shell::OPTIONS[:prompt]
|
37
|
+
}.should =~ /ripl: Error while creating.*NameError.*`wtf'/m
|
38
|
+
end
|
33
39
|
end
|
34
40
|
|
35
41
|
describe "#before_loop" do
|
36
42
|
before_all { Ripl::Commands.send(:define_method, :ping) { 'pong' } }
|
37
43
|
it "adds commands to main from Commands" do
|
38
44
|
stub(Ripl::Runner).load_rc
|
45
|
+
stub(Kernel).at_exit
|
39
46
|
Ripl.shell.before_loop
|
40
47
|
Ripl.shell.loop_eval("ping").should == 'pong'
|
41
48
|
end
|
@@ -43,6 +50,7 @@ describe "Shell" do
|
|
43
50
|
it "adds commands to fixnum from Commands" do
|
44
51
|
stub(Ripl::Runner).load_rc
|
45
52
|
Ripl.shell.binding = 1.send(:binding)
|
53
|
+
stub(Kernel).at_exit
|
46
54
|
Ripl.shell.before_loop
|
47
55
|
Ripl.shell.loop_eval("ping").should == 'pong'
|
48
56
|
end
|
data/test/test_helper.rb
CHANGED
@@ -9,13 +9,21 @@ include Ripl
|
|
9
9
|
module Helpers
|
10
10
|
def ripl(*args)
|
11
11
|
options = args[-1].is_a?(Hash) ? args.pop : {}
|
12
|
-
|
12
|
+
mock_riplrc unless options[:riplrc] == false
|
13
13
|
mock(Runner).start if options[:start]
|
14
14
|
capture_stdout { Ripl::Runner.run(args) }
|
15
15
|
end
|
16
16
|
|
17
17
|
def mock_riplrc(&block)
|
18
|
-
mock(Runner).load_rc(Ripl.config[:riplrc]
|
18
|
+
mock(Runner).load_rc(Ripl.config[:riplrc], &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def mock_shell(&block)
|
22
|
+
mock(Shell).create(anything) {|e|
|
23
|
+
shell = Shell.new(e)
|
24
|
+
block ? block.call(shell) : mock(shell).loop
|
25
|
+
shell
|
26
|
+
}
|
19
27
|
end
|
20
28
|
|
21
29
|
def reset_ripl
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabriel Horner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-24 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -56,14 +56,14 @@ dependencies:
|
|
56
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
61
|
+
hash: 23
|
62
62
|
segments:
|
63
|
+
- 1
|
64
|
+
- 0
|
63
65
|
- 0
|
64
|
-
|
65
|
-
- 10
|
66
|
-
version: 0.10.10
|
66
|
+
version: 1.0.0
|
67
67
|
type: :development
|
68
68
|
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|