ripl 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/README.rdoc +5 -3
- data/lib/ripl/history.rb +2 -3
- data/lib/ripl/readline.rb +1 -1
- data/lib/ripl/runner.rb +29 -18
- data/lib/ripl/shell.rb +9 -6
- data/lib/ripl/version.rb +1 -1
- data/lib/ripl.rb +2 -2
- data/test/history_test.rb +14 -0
- data/test/runner_test.rb +10 -0
- data/test/shell_test.rb +5 -0
- metadata +5 -5
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -75,7 +75,7 @@ modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:
|
|
75
75
|
* IRB.conf -> Ripl.config
|
76
76
|
* Handles Ctrl-C quietly
|
77
77
|
* Enhancements over irb
|
78
|
-
* ~
|
78
|
+
* ~290 lines (doc included) vs irb's 5000+ lines
|
79
79
|
* Easily extendable with plugins
|
80
80
|
* Tests and documentation!
|
81
81
|
* Customizable completion and completion of method arguments (from bond)
|
@@ -84,6 +84,7 @@ modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:
|
|
84
84
|
* Create console commands in a simple, modular way
|
85
85
|
* Custom commandline options can be added via a plugin
|
86
86
|
* ~/.irbrc errors caught
|
87
|
+
* Well-integrated internationalization (see {ripl-i18n}[http://github.com/cldwalker/ripl-i18n])
|
87
88
|
* Different from irb
|
88
89
|
* No multi-line evaluation by default (but there is a plugin,
|
89
90
|
{ripl-multi_line}[http://github.com/janlelis/ripl-multi_line]).
|
@@ -151,8 +152,8 @@ command you can take arguments and parse your options as you please. For an exam
|
|
151
152
|
see {ripl-rails}[http://github.com/cldwalker/ripl-rails].
|
152
153
|
|
153
154
|
== Credits
|
154
|
-
* janlelis for bug fix and tweaks
|
155
|
-
*
|
155
|
+
* janlelis and godfat for bug fix and tweaks
|
156
|
+
* JoshCheek for bug fixes
|
156
157
|
|
157
158
|
== Ripl Plugins
|
158
159
|
|
@@ -164,6 +165,7 @@ see {ripl-rails}[http://github.com/cldwalker/ripl-rails].
|
|
164
165
|
* {ripl-debug}[http://github.com/cldwalker/ripl-debug] : automatically debugs a failed eval
|
165
166
|
* {ripl-after_rc}[http://github.com/cldwalker/ripl-after_rc] : provide blocks to run after ~/.irbrc is loaded
|
166
167
|
* {ripl-irb}[http://github.com/cldwalker/ripl-irb] : smooths transition from irb
|
168
|
+
* {ripl-i18n}[http://github.com/cldwalker/ripl-i18n] : translates ripl to your language
|
167
169
|
* {ripl-commands}[http://github.com/cldwalker/ripl-commands] : adds ripl commands similar to irb's commands
|
168
170
|
* {ripl-color_error}[http://github.com/cldwalker/ripl-color_error] : colorize errors
|
169
171
|
* {ripl-color_streams}[http://github.com/janlelis/ripl-color_streams] : colorizes stderr + stdout
|
data/lib/ripl/history.rb
CHANGED
@@ -3,14 +3,13 @@ module Ripl::History
|
|
3
3
|
@history_file ||= File.expand_path(config[:history])
|
4
4
|
end
|
5
5
|
|
6
|
-
def history
|
6
|
+
def history() @history ||= [] end
|
7
7
|
|
8
8
|
def get_input
|
9
9
|
(@history << super)[-1]
|
10
10
|
end
|
11
11
|
|
12
12
|
def before_loop
|
13
|
-
@history = []
|
14
13
|
super
|
15
14
|
File.exists?(history_file) &&
|
16
15
|
IO.readlines(history_file).each {|e| history << e.chomp }
|
@@ -19,7 +18,7 @@ module Ripl::History
|
|
19
18
|
def write_history
|
20
19
|
File.open(history_file, 'w') {|f| f.write Array(history).join("\n") }
|
21
20
|
end
|
22
|
-
def after_loop
|
21
|
+
def after_loop() write_history end
|
23
22
|
end
|
24
23
|
Ripl::Shell.include Ripl::History
|
25
24
|
Ripl.config[:history] = '~/.irb_history'
|
data/lib/ripl/readline.rb
CHANGED
data/lib/ripl/runner.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
class Ripl::Runner
|
2
|
-
|
3
|
-
|
4
|
-
['-
|
5
|
-
['-
|
6
|
-
['-
|
7
|
-
|
8
|
-
['-
|
9
|
-
['-
|
10
|
-
|
2
|
+
OPTIONS_ARR = %w{-f -F -d -I -r -v -h}
|
3
|
+
OPTIONS = {
|
4
|
+
'-f' => ['-f', 'Suppress loading ~/.irbrc'],
|
5
|
+
'-F' => ['-F', 'Suppress loading ~/.riplrc'],
|
6
|
+
'-d' => ['-d, --debug', "Set $DEBUG to true (same as `ruby -d')"],
|
7
|
+
'-I' => ['-I PATH', "Add to front of $LOAD_PATH. Delimit multiple paths with ':'"],
|
8
|
+
'-r' => ['-r, --require FILE', "Require file (same as `ruby -r')"],
|
9
|
+
'-v' => ['-v, --version', 'Print version'],
|
10
|
+
'-h' => ['-h, --help', 'Print help']
|
11
|
+
}
|
12
|
+
MESSAGES = {
|
13
|
+
'run_command' => "`%s' is not a %s command.",
|
14
|
+
'start' => "Unused arguments",
|
15
|
+
'load_rc' => 'Error while loading %s',
|
16
|
+
'parse_option' => 'invalid option'
|
17
|
+
}
|
18
|
+
|
11
19
|
class <<self; attr_accessor :argv, :app; end
|
12
20
|
self.app = 'ripl'
|
13
21
|
|
14
22
|
# Adds commandline options for --help
|
15
23
|
def self.add_options(*options)
|
16
|
-
|
24
|
+
options.each {|e|
|
25
|
+
OPTIONS[e[0][/-\w+/]] = e
|
26
|
+
OPTIONS_ARR << e[0][/-\w+/]
|
27
|
+
}
|
17
28
|
end
|
18
29
|
|
19
30
|
def self.run(argv=ARGV)
|
@@ -24,7 +35,7 @@ class Ripl::Runner
|
|
24
35
|
exec "#{app}-#{argv.shift}", *argv
|
25
36
|
rescue Errno::ENOENT
|
26
37
|
raise unless $!.message =~ /No such file or directory.*#{app}-(\w+)/
|
27
|
-
abort
|
38
|
+
abort MESSAGES['run_command'] % [$1, app]
|
28
39
|
end
|
29
40
|
|
30
41
|
def self.start(options={})
|
@@ -33,14 +44,14 @@ class Ripl::Runner
|
|
33
44
|
load_rc(Ripl.config[:riplrc]) unless argv.delete('-F') || options[:riplrc] == false
|
34
45
|
argv.each {|e| e[/^-/] ? break : argv.shift } if $0[/#{app}-\w+$/]
|
35
46
|
parse_options(argv) if $0[/#{app}$|#{app}-\w+$/]
|
36
|
-
warn "#{app}:
|
47
|
+
warn "#{app}: #{MESSAGES['start']}: #{argv.inspect}" if !argv.empty?
|
37
48
|
Ripl.shell(options).loop
|
38
49
|
end
|
39
50
|
|
40
51
|
def self.load_rc(file)
|
41
52
|
load file if File.exists?(File.expand_path(file))
|
42
53
|
rescue StandardError, SyntaxError, LoadError
|
43
|
-
warn "#{app}:
|
54
|
+
warn "#{app}: #{MESSAGES['load_rc'] % file}:\n"+ format_error($!)
|
44
55
|
end
|
45
56
|
|
46
57
|
module API
|
@@ -61,14 +72,14 @@ class Ripl::Runner
|
|
61
72
|
|
62
73
|
def help
|
63
74
|
return("#{app} #{$1} [ARGS] [OPTIONS]") if $0[/#{app}-(\w+)/]
|
64
|
-
name_max = OPTIONS.map {|e| e[0].length }.max
|
65
|
-
desc_max = OPTIONS.map {|e| e[1].length }.max
|
66
|
-
["Usage: #{app} [COMMAND] [ARGS] [OPTIONS]", "\nOptions:",
|
67
|
-
|
75
|
+
name_max = OPTIONS.values.map {|e| e[0].length }.max
|
76
|
+
desc_max = OPTIONS.values.map {|e| e[1].length }.max
|
77
|
+
["Usage: #{app} [COMMAND] [ARGS] [OPTIONS]", "\nOptions:", OPTIONS_ARR.
|
78
|
+
map {|e| n,d = OPTIONS[e]; " %-*s %-*s" % [name_max, n, desc_max, d] }]
|
68
79
|
end
|
69
80
|
|
70
81
|
def parse_option(option, argv)
|
71
|
-
warn "#{app}:
|
82
|
+
warn "#{app}: #{MESSAGES['parse_option']} `#{option.sub(/^-+/, '')}'"
|
72
83
|
end
|
73
84
|
|
74
85
|
def format_error(err)
|
data/lib/ripl/shell.rb
CHANGED
@@ -27,13 +27,16 @@ class Ripl::Shell
|
|
27
27
|
# Loops shell until user exits
|
28
28
|
def loop
|
29
29
|
before_loop
|
30
|
-
catch(:ripl_exit) { while(true)
|
30
|
+
catch(:ripl_exit) { loop_once while(true) }
|
31
31
|
after_loop
|
32
32
|
end
|
33
33
|
|
34
|
-
def config
|
34
|
+
def config() Ripl.config end
|
35
35
|
|
36
36
|
module API
|
37
|
+
MESSAGES = {'prompt' => 'Error while creating prompt',
|
38
|
+
'print_result' => 'Error while printing result'}
|
39
|
+
|
37
40
|
attr_accessor :prompt, :result_prompt
|
38
41
|
# Sets up shell before looping by loading ~/.irbrc. Can be extended to
|
39
42
|
# initialize plugins and their instance variables.
|
@@ -59,7 +62,7 @@ class Ripl::Shell
|
|
59
62
|
end
|
60
63
|
|
61
64
|
# Handles interrupt (Control-C) by printing a newline
|
62
|
-
def handle_interrupt
|
65
|
+
def handle_interrupt() puts end
|
63
66
|
|
64
67
|
# Sets @result to result of evaling input and print unexpected errors
|
65
68
|
def eval_input(input)
|
@@ -84,7 +87,7 @@ class Ripl::Shell
|
|
84
87
|
def prompt
|
85
88
|
@prompt.respond_to?(:call) ? @prompt.call : @prompt
|
86
89
|
rescue StandardError, SyntaxError
|
87
|
-
warn "ripl:
|
90
|
+
warn "ripl: #{MESSAGES['prompt']}:\n"+ format_error($!)
|
88
91
|
OPTIONS[:prompt]
|
89
92
|
end
|
90
93
|
|
@@ -104,13 +107,13 @@ class Ripl::Shell
|
|
104
107
|
def print_result(result)
|
105
108
|
puts(format_result(result)) unless @error_raised
|
106
109
|
rescue StandardError, SyntaxError
|
107
|
-
warn "ripl:
|
110
|
+
warn "ripl: #{MESSAGES['print_result']}:\n"+ format_error($!)
|
108
111
|
end
|
109
112
|
|
110
113
|
# Formats errors raised by eval of user input
|
111
114
|
# @param [Exception]
|
112
115
|
# @return [String]
|
113
|
-
def format_error(err)
|
116
|
+
def format_error(err) Ripl::Runner.format_error(err) end
|
114
117
|
|
115
118
|
# @return [String] Formats result using result_prompt
|
116
119
|
def format_result(result)
|
data/lib/ripl/version.rb
CHANGED
data/lib/ripl.rb
CHANGED
@@ -3,8 +3,8 @@ module Ripl
|
|
3
3
|
@config ||= {:readline => true, :riplrc => '~/.riplrc', :completion => {}}
|
4
4
|
end
|
5
5
|
|
6
|
-
def self.start(*args)
|
7
|
-
def self.started
|
6
|
+
def self.start(*args) Runner.start(*args) end
|
7
|
+
def self.started?() instance_variable_defined?(:@shell) end
|
8
8
|
|
9
9
|
def self.plugins
|
10
10
|
file = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
data/test/history_test.rb
CHANGED
@@ -44,4 +44,18 @@ describe "History with readline" do
|
|
44
44
|
shell.after_loop
|
45
45
|
shell.history.should == ['pong_write_history']
|
46
46
|
end
|
47
|
+
|
48
|
+
it "#history is overridable in #write_history when readline is enabled" do
|
49
|
+
stub(Shell).include(is_a(Module)){} # try to avoid side-effect...
|
50
|
+
require 'ripl/readline'
|
51
|
+
SandboxShell = Shell.dup
|
52
|
+
SandboxShell.send :include, Ripl::Readline
|
53
|
+
sandbox_shell = SandboxShell.create(:readline => true)
|
54
|
+
|
55
|
+
mod = Module.new { def write_history() @history = ['updated_history'] end }
|
56
|
+
SandboxShell.send :include, mod
|
57
|
+
|
58
|
+
sandbox_shell.after_loop
|
59
|
+
sandbox_shell.history.should == ['updated_history']
|
60
|
+
end
|
47
61
|
end
|
data/test/runner_test.rb
CHANGED
@@ -294,6 +294,16 @@ describe "Runner" do
|
|
294
294
|
Runner.send(meth).should == "pong_#{meth}"
|
295
295
|
end
|
296
296
|
end
|
297
|
+
|
298
|
+
it "Runner::MESSAGES only calls #[]" do
|
299
|
+
str = File.read(File.dirname(__FILE__)+'/../lib/ripl/runner.rb')
|
300
|
+
str.scan(/MESSAGES\S+/).all? {|e| e[/MESSAGES\[/] }.should == true
|
301
|
+
end
|
302
|
+
|
303
|
+
it "Runner::OPTIONS only calls #[] and values" do
|
304
|
+
str = File.read(File.dirname(__FILE__)+'/../lib/ripl/runner.rb')
|
305
|
+
str.scan(/OPTIONS[^_\] ]\S+/).all? {|e| e[/OPTIONS(\[|\.values)/] }.should == true
|
306
|
+
end
|
297
307
|
after_all { Runner.extend Runner::API }
|
298
308
|
end
|
299
309
|
end
|
data/test/shell_test.rb
CHANGED
@@ -136,5 +136,10 @@ describe "Shell" do
|
|
136
136
|
shell.send(meth).should == "pong_#{meth}"
|
137
137
|
end
|
138
138
|
end
|
139
|
+
|
140
|
+
it "Shell::MESSAGES only calls #[]" do
|
141
|
+
str = File.read(File.dirname(__FILE__)+'/../lib/ripl/shell.rb')
|
142
|
+
str.scan(/MESSAGES\S+/).all? {|e| e[/MESSAGES\[/] }.should == true
|
143
|
+
end
|
139
144
|
end
|
140
145
|
end
|
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: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
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: 2011-
|
18
|
+
date: 2011-05-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|