ripl 0.6.4 → 0.7.0
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 +4 -0
- data/README.rdoc +1 -0
- data/deps.rip +1 -1
- data/lib/ripl/history.rb +6 -3
- data/lib/ripl/runner.rb +4 -4
- data/lib/ripl/shell.rb +16 -9
- data/lib/ripl/version.rb +1 -1
- data/test/history_test.rb +38 -17
- data/test/runner_test.rb +7 -4
- data/test/shell_test.rb +2 -2
- metadata +5 -5
data/.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.description = "ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports commands i.e. ripl-play. This customizability makes it easy to build custom shells (i.e. for a gem or application) and complex shells (i.e. for the web). In other words, ripl is also a shell framework. Works on ruby 1.8.7 and greater."
|
13
13
|
s.required_rubygems_version = ">= 1.3.6"
|
14
14
|
s.executables = %w(ripl)
|
15
|
-
s.add_dependency 'bond', '~> 0.4.
|
15
|
+
s.add_dependency 'bond', '~> 0.4.2'
|
16
16
|
s.add_development_dependency 'bacon', '>= 1.1.0'
|
17
17
|
s.add_development_dependency 'rr', '>= 1.0.4'
|
18
18
|
s.add_development_dependency 'bacon-bits'
|
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -155,6 +155,7 @@ see {ripl-rails}[http://github.com/cldwalker/ripl-rails].
|
|
155
155
|
== Credits
|
156
156
|
* janlelis and godfat for bug fix and tweaks
|
157
157
|
* JoshCheek for bug fixes
|
158
|
+
* postmodern for windows fixes and no history support
|
158
159
|
|
159
160
|
== Bugs/Issues
|
160
161
|
Please report them {on github}[http://github.com/cldwalker/ripl/issues].
|
data/deps.rip
CHANGED
@@ -1 +1 @@
|
|
1
|
-
bond ~>0.4.
|
1
|
+
bond ~>0.4.2
|
data/lib/ripl/history.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ripl::History
|
2
2
|
def history_file
|
3
|
-
@history_file ||= File.expand_path(config[:history])
|
3
|
+
@history_file ||= config[:history] && File.expand_path(config[:history])
|
4
4
|
end
|
5
5
|
|
6
6
|
def history() @history ||= [] end
|
@@ -10,12 +10,15 @@ module Ripl::History
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def read_history
|
13
|
-
File.exists?(history_file) && history.empty?
|
13
|
+
if ((history_file && File.exists?(history_file)) && history.empty?)
|
14
14
|
IO.readlines(history_file).each {|e| history << e.chomp }
|
15
|
+
end
|
15
16
|
end
|
16
17
|
|
17
18
|
def write_history
|
18
|
-
|
19
|
+
if history_file
|
20
|
+
File.open(history_file, 'w') {|f| f.puts(*Array(history)) }
|
21
|
+
end
|
19
22
|
end
|
20
23
|
def before_loop() super; read_history end
|
21
24
|
def after_loop() super; write_history end
|
data/lib/ripl/runner.rb
CHANGED
@@ -16,7 +16,7 @@ class Ripl::Runner
|
|
16
16
|
'parse_option' => 'invalid option'
|
17
17
|
}
|
18
18
|
|
19
|
-
class <<self; attr_accessor :argv, :app; end
|
19
|
+
class << self; attr_accessor :argv, :app; end
|
20
20
|
self.app = 'ripl'
|
21
21
|
|
22
22
|
# Adds commandline options for --help
|
@@ -52,7 +52,7 @@ class Ripl::Runner
|
|
52
52
|
def self.load_rc(file)
|
53
53
|
load file if File.exists?(File.expand_path(file))
|
54
54
|
rescue StandardError, SyntaxError, LoadError
|
55
|
-
|
55
|
+
$stderr.puts "#{app}: #{MESSAGES['load_rc'] % file}:", format_error($!)
|
56
56
|
end
|
57
57
|
|
58
58
|
module API
|
@@ -77,7 +77,7 @@ class Ripl::Runner
|
|
77
77
|
desc_max = OPTIONS.values.map {|e| e[1].length }.max
|
78
78
|
m = MESSAGES
|
79
79
|
["%s: #{app} [%s] [%s] [%s]" % ( [m['usage'], m['command'], m['args'],
|
80
|
-
m['options'].upcase] ), "
|
80
|
+
m['options'].upcase] ), "#{$/}#{m['options']}:", OPTIONS_ARR.
|
81
81
|
map {|e| n,d = OPTIONS[e]; " %-*s %-*s" % [name_max, n, desc_max, d] }]
|
82
82
|
end
|
83
83
|
|
@@ -87,7 +87,7 @@ class Ripl::Runner
|
|
87
87
|
|
88
88
|
def format_error(err)
|
89
89
|
stack = err.backtrace.take_while {|line| line !~ %r{/ripl/\S+\.rb} }
|
90
|
-
"#{err.class}: #{err.message}
|
90
|
+
"#{err.class}: #{err.message}#{$/} #{stack.join("#{$/} ")}"
|
91
91
|
end
|
92
92
|
end
|
93
93
|
extend API
|
data/lib/ripl/shell.rb
CHANGED
@@ -10,10 +10,15 @@ class Ripl::Shell
|
|
10
10
|
new(options)
|
11
11
|
end
|
12
12
|
|
13
|
-
class <<self; public :include; end
|
14
|
-
|
15
|
-
OPTIONS = {
|
16
|
-
:
|
13
|
+
class << self; public :include; end
|
14
|
+
|
15
|
+
OPTIONS = {
|
16
|
+
:name => 'ripl',
|
17
|
+
:result_prompt => '=> ',
|
18
|
+
:prompt => '>> ',
|
19
|
+
:binding => TOPLEVEL_BINDING,
|
20
|
+
:irbrc=>'~/.irbrc'
|
21
|
+
}
|
17
22
|
EXIT_WORDS = [nil, 'exit', 'quit']
|
18
23
|
|
19
24
|
attr_accessor :line, :binding, :result, :name, :input
|
@@ -34,8 +39,10 @@ class Ripl::Shell
|
|
34
39
|
def config() Ripl.config end
|
35
40
|
|
36
41
|
module API
|
37
|
-
MESSAGES = {
|
38
|
-
'
|
42
|
+
MESSAGES = {
|
43
|
+
'prompt' => 'Error while creating prompt',
|
44
|
+
'print_result' => 'Error while printing result'
|
45
|
+
}
|
39
46
|
|
40
47
|
attr_accessor :prompt, :result_prompt
|
41
48
|
# Sets up shell before looping by loading ~/.irbrc. Can be extended to
|
@@ -91,7 +98,7 @@ class Ripl::Shell
|
|
91
98
|
def prompt
|
92
99
|
@prompt.respond_to?(:call) ? @prompt.call : @prompt
|
93
100
|
rescue StandardError, SyntaxError
|
94
|
-
|
101
|
+
$stderr.puts "ripl: #{MESSAGES['prompt']}:", format_error($!)
|
95
102
|
OPTIONS[:prompt]
|
96
103
|
end
|
97
104
|
|
@@ -104,14 +111,14 @@ class Ripl::Shell
|
|
104
111
|
# handle certain exceptions.
|
105
112
|
# @param [Exception]
|
106
113
|
def print_eval_error(err)
|
107
|
-
|
114
|
+
$stderr.puts format_error(err)
|
108
115
|
end
|
109
116
|
|
110
117
|
# Prints result using #format_result
|
111
118
|
def print_result(result)
|
112
119
|
puts(format_result(result)) unless @error_raised
|
113
120
|
rescue StandardError, SyntaxError
|
114
|
-
|
121
|
+
$stderr.puts "ripl: #{MESSAGES['print_result']}:", format_error($!)
|
115
122
|
end
|
116
123
|
|
117
124
|
# Formats errors raised by eval of user input
|
data/lib/ripl/version.rb
CHANGED
data/test/history_test.rb
CHANGED
@@ -8,6 +8,12 @@ describe "History with readline" do
|
|
8
8
|
Ripl.shell(:history => HISTORY_FILE, :readline => false, :completion => false)
|
9
9
|
end
|
10
10
|
|
11
|
+
def history_must_equal(history, sh=shell)
|
12
|
+
stub(Ripl::Runner).load_rc
|
13
|
+
sh.before_loop
|
14
|
+
sh.history.to_a.should == history
|
15
|
+
end
|
16
|
+
|
11
17
|
before_all { reset_shell }
|
12
18
|
before do
|
13
19
|
reset_ripl
|
@@ -18,32 +24,26 @@ describe "History with readline" do
|
|
18
24
|
after { FileUtils.rm_f HISTORY_FILE }
|
19
25
|
|
20
26
|
it "#after_loop saves history" do
|
21
|
-
inputs = %w
|
27
|
+
inputs = %w[blih blah]
|
22
28
|
shell.instance_variable_set '@history', inputs
|
23
29
|
shell.after_loop
|
24
|
-
File.read(HISTORY_FILE).should == inputs.join(
|
30
|
+
File.read(HISTORY_FILE).should == inputs.join($/) + $/
|
25
31
|
end
|
26
32
|
|
27
33
|
it "#before_loop loads previous history" do
|
28
|
-
File.open(HISTORY_FILE, 'w') {|f| f.write
|
29
|
-
|
30
|
-
shell.before_loop
|
31
|
-
shell.history.to_a.should == %w{check the mike}
|
34
|
+
File.open(HISTORY_FILE, 'w') {|f| f.write %w[check the mike].join($/) }
|
35
|
+
history_must_equal %w{check the mike}
|
32
36
|
end
|
33
37
|
|
34
38
|
it "#before_loop loads previous history only when it's empty" do
|
35
|
-
File.open(HISTORY_FILE, 'w') {|f| f.write
|
36
|
-
|
37
|
-
history = %w{already there}
|
39
|
+
File.open(HISTORY_FILE, 'w') {|f| f.write %w[check the mike].join($/) }
|
40
|
+
history = %w[already there]
|
38
41
|
shell.instance_variable_set(:@history, history.dup)
|
39
|
-
|
40
|
-
shell.history.to_a.should == history
|
42
|
+
history_must_equal history
|
41
43
|
end
|
42
44
|
|
43
45
|
it "#before_loop has empty history if no history file exists" do
|
44
|
-
|
45
|
-
shell.before_loop
|
46
|
-
shell.history.to_a.should == []
|
46
|
+
history_must_equal []
|
47
47
|
end
|
48
48
|
|
49
49
|
it "#get_input adds to history" do
|
@@ -56,9 +56,7 @@ describe "History with readline" do
|
|
56
56
|
mod = Object.const_set "Ping_read_history", Module.new
|
57
57
|
mod.send(:define_method, 'read_history') { @history = ['pong_read_history'] }
|
58
58
|
Shell.send :include, mod
|
59
|
-
|
60
|
-
shell.before_loop
|
61
|
-
shell.history.should == ['pong_read_history']
|
59
|
+
history_must_equal ['pong_read_history']
|
62
60
|
end
|
63
61
|
|
64
62
|
it "#write_history is accessible to plugins in #after_loop" do
|
@@ -82,4 +80,27 @@ describe "History with readline" do
|
|
82
80
|
sandbox_shell.after_loop
|
83
81
|
sandbox_shell.history.should == ['updated_history']
|
84
82
|
end
|
83
|
+
|
84
|
+
describe "with no history_file" do
|
85
|
+
def shell
|
86
|
+
Ripl.shell(:history => false)
|
87
|
+
end
|
88
|
+
|
89
|
+
before_all do
|
90
|
+
FileUtils.touch(HISTORY_FILE)
|
91
|
+
reset_shell
|
92
|
+
end
|
93
|
+
|
94
|
+
it "#after_loop does not save history" do
|
95
|
+
inputs = %w{blih blah}
|
96
|
+
shell.instance_variable_set '@history', inputs
|
97
|
+
shell.after_loop
|
98
|
+
File.read(HISTORY_FILE).should == ''
|
99
|
+
end
|
100
|
+
|
101
|
+
it "#before_loop does not load history" do
|
102
|
+
File.open(HISTORY_FILE, 'w') {|f| f.puts 'check', 'the', 'mike' }
|
103
|
+
history_must_equal [], shell
|
104
|
+
end
|
105
|
+
end
|
85
106
|
end
|
data/test/runner_test.rb
CHANGED
@@ -67,13 +67,13 @@ describe "Runner" do
|
|
67
67
|
it "rescues and prints SyntaxError" do
|
68
68
|
mock(Runner).load(anything) { raise SyntaxError }
|
69
69
|
mock_shell
|
70
|
-
capture_stderr { Runner.run([]) }.should =~ %r{^ripl: Error while loading .*.riplrc
|
70
|
+
capture_stderr { Runner.run([]) }.should =~ %r{^ripl: Error while loading .*.riplrc:#{$/}SyntaxError:}
|
71
71
|
end
|
72
72
|
|
73
73
|
it "rescues and prints LoadError" do
|
74
74
|
mock(Runner).load(anything) { raise LoadError }
|
75
75
|
mock_shell
|
76
|
-
capture_stderr { Runner.run([]) }.should =~ %r{^ripl: Error while loading .*.riplrc
|
76
|
+
capture_stderr { Runner.run([]) }.should =~ %r{^ripl: Error while loading .*.riplrc:#{$/}LoadError:}
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -229,13 +229,16 @@ describe "Runner" do
|
|
229
229
|
mock(Runner).exit
|
230
230
|
actual = ripl("-h")
|
231
231
|
actual.should =~ /^Usage: ripl/
|
232
|
-
actual.should =~ /Options
|
232
|
+
actual.should =~ /Options:#{$/} -f/
|
233
233
|
end
|
234
234
|
|
235
235
|
it "with invalid options prints errors" do
|
236
236
|
capture_stderr {
|
237
237
|
ripl('--blah', '-z')
|
238
|
-
}.chomp.should ==
|
238
|
+
}.chomp.should == [
|
239
|
+
"ripl: invalid option `blah'",
|
240
|
+
"ripl: invalid option `z'"
|
241
|
+
].join($/)
|
239
242
|
end
|
240
243
|
|
241
244
|
describe "with plugin" do
|
data/test/shell_test.rb
CHANGED
@@ -32,12 +32,12 @@ describe "Shell" do
|
|
32
32
|
it "handles Control-C" do
|
33
33
|
mock(shell).get_input { raise Interrupt }
|
34
34
|
dont_allow(shell).eval_input
|
35
|
-
capture_stdout { shell.loop_once }.should ==
|
35
|
+
capture_stdout { shell.loop_once }.should == $/
|
36
36
|
end
|
37
37
|
|
38
38
|
it "prints result" do
|
39
39
|
mock(shell).get_input { '"m" * 2' }
|
40
|
-
capture_stdout { shell.loop_once }.should ==
|
40
|
+
capture_stdout { shell.loop_once }.should == '=> "mm"' + $/
|
41
41
|
end
|
42
42
|
|
43
43
|
it "prints error from a failed result" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bond
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.4.
|
21
|
+
version: 0.4.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.4.
|
29
|
+
version: 0.4.2
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bacon
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
151
|
version: 1.3.6
|
152
152
|
requirements: []
|
153
153
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.8.
|
154
|
+
rubygems_version: 1.8.24
|
155
155
|
signing_key:
|
156
156
|
specification_version: 3
|
157
157
|
summary: ruby interactive print loop - A light, modular alternative to irb and a shell
|