ripl 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +4 -2
- data/deps.rip +1 -1
- data/lib/ripl/completion.rb +2 -1
- data/lib/ripl/shell.rb +43 -25
- data/lib/ripl/version.rb +1 -1
- data/man/ripl.1 +7 -7
- data/man/ripl.1.ronn +9 -9
- data/test/runner_test.rb +9 -9
- metadata +4 -4
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
|
+
* ~230 lines 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)
|
@@ -83,7 +83,9 @@ loading them as early as possible and allowing them to extend most of ripl's fun
|
|
83
83
|
|
84
84
|
As an example plugin, let's color error messages red:
|
85
85
|
|
86
|
-
|
86
|
+
require 'ripl'
|
87
|
+
|
88
|
+
# To try place in ~/.riplrc
|
87
89
|
module Ripl
|
88
90
|
module RedError
|
89
91
|
def format_error(error)
|
data/deps.rip
CHANGED
@@ -1 +1 @@
|
|
1
|
-
bond ~>0.3.
|
1
|
+
bond ~>0.3.3
|
data/lib/ripl/completion.rb
CHANGED
@@ -3,7 +3,8 @@ require 'bond'
|
|
3
3
|
module Ripl::Completion
|
4
4
|
def before_loop
|
5
5
|
super
|
6
|
-
|
6
|
+
options = {:eval_binding=>lambda { Ripl.shell.binding }}
|
7
|
+
Bond.restart((config[:completion] || {}).merge(options))
|
7
8
|
end
|
8
9
|
end
|
9
10
|
Ripl::Shell.send :include, Ripl::Completion
|
data/lib/ripl/shell.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Ripl::Shell
|
2
|
-
OPTIONS = {:name=>'ripl', :
|
2
|
+
OPTIONS = {:name=>'ripl', :result_prompt=>'=> ', :prompt=>'>> ',
|
3
3
|
:binding=>TOPLEVEL_BINDING, :irbrc=>'~/.irbrc'}
|
4
4
|
|
5
5
|
def self.create(options={})
|
@@ -10,13 +10,15 @@ class Ripl::Shell
|
|
10
10
|
new(options)
|
11
11
|
end
|
12
12
|
|
13
|
-
attr_accessor :line, :binding, :result_prompt, :result, :
|
13
|
+
attr_accessor :line, :binding, :result_prompt, :result, :name
|
14
14
|
def initialize(options={})
|
15
|
-
|
16
|
-
@name, @binding
|
17
|
-
@
|
15
|
+
options = OPTIONS.merge options
|
16
|
+
@name, @binding = options.values_at(:name, :binding)
|
17
|
+
@prompt, @result_prompt = options.values_at(:prompt, :result_prompt)
|
18
|
+
@irbrc, @line = options[:irbrc], 1
|
18
19
|
end
|
19
20
|
|
21
|
+
# Loops shell until user exits
|
20
22
|
def loop
|
21
23
|
before_loop
|
22
24
|
catch(:ripl_exit) { while(true) do; loop_once; end }
|
@@ -25,56 +27,72 @@ class Ripl::Shell
|
|
25
27
|
|
26
28
|
def config; Ripl.config; end
|
27
29
|
|
30
|
+
# Runs through one loop iteration: gets input, evals and prints result
|
31
|
+
def loop_once
|
32
|
+
@error_raised = nil
|
33
|
+
@input = get_input
|
34
|
+
throw(:ripl_exit) if !@input || @input == 'exit'
|
35
|
+
eval_input(@input)
|
36
|
+
print_result(@result)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Sets @result to result of evaling input and print unexpected errors
|
40
|
+
def eval_input(input)
|
41
|
+
@result = loop_eval(input)
|
42
|
+
eval("_ = Ripl.shell.result", @binding)
|
43
|
+
rescue Exception => e
|
44
|
+
@error_raised = true
|
45
|
+
print_eval_error(e)
|
46
|
+
ensure
|
47
|
+
@line += 1
|
48
|
+
end
|
49
|
+
|
28
50
|
module API
|
51
|
+
# Sets up shell before looping by loading ~/.irbrc. Can be extended to
|
52
|
+
# initialize plugins and their instance variables.
|
29
53
|
def before_loop
|
30
54
|
Ripl::Runner.load_rc(@irbrc) if @irbrc
|
31
55
|
end
|
32
56
|
|
33
|
-
|
34
|
-
@error_raised = nil
|
35
|
-
@input = get_input
|
36
|
-
throw(:ripl_exit) if !@input || @input == 'exit'
|
37
|
-
eval_input(@input)
|
38
|
-
print_result(@result)
|
39
|
-
end
|
40
|
-
|
57
|
+
# @return [String, nil] Prints #prompt and returns input given by user
|
41
58
|
def get_input
|
42
59
|
print prompt
|
43
60
|
$stdin.gets.chomp
|
44
61
|
end
|
45
62
|
|
63
|
+
# @return [String]
|
46
64
|
def prompt
|
47
|
-
@
|
48
|
-
end
|
49
|
-
|
50
|
-
def eval_input(input)
|
51
|
-
@result = loop_eval(input)
|
52
|
-
eval("_ = Ripl.shell.result", @binding)
|
53
|
-
rescue Exception => e
|
54
|
-
@error_raised = true
|
55
|
-
print_eval_error(e)
|
56
|
-
ensure
|
57
|
-
@line += 1
|
65
|
+
@prompt.respond_to?(:call) ? @prompt.call : @prompt
|
58
66
|
end
|
59
67
|
|
68
|
+
# Evals user input using @binding, @name and @line
|
60
69
|
def loop_eval(str)
|
61
70
|
eval(str, @binding, "(#{@name})", @line)
|
62
71
|
end
|
63
72
|
|
73
|
+
# Prints error formatted by #format_error to STDERR. Could be extended to
|
74
|
+
# handle certain exceptions.
|
75
|
+
# @param [Exception]
|
64
76
|
def print_eval_error(err)
|
65
77
|
warn format_error(err)
|
66
78
|
end
|
67
79
|
|
80
|
+
# Prints result using #format_result
|
68
81
|
def print_result(result)
|
69
82
|
puts(format_result(result)) unless @error_raised
|
70
83
|
end
|
71
84
|
|
85
|
+
# Formats errors raised by eval of user input
|
86
|
+
# @param [Exception]
|
87
|
+
# @return [String]
|
72
88
|
def format_error(err); Ripl::Runner.format_error(err); end
|
73
89
|
|
90
|
+
# @return [String] Formats result using result_prompt
|
74
91
|
def format_result(result)
|
75
|
-
@
|
92
|
+
@result_prompt + result.inspect
|
76
93
|
end
|
77
94
|
|
95
|
+
# Called after shell finishes looping.
|
78
96
|
def after_loop; end
|
79
97
|
end
|
80
98
|
include API
|
data/lib/ripl/version.rb
CHANGED
data/man/ripl.1
CHANGED
@@ -112,7 +112,9 @@ For an example shell plugin, let\'s color error messages red:
|
|
112
112
|
.
|
113
113
|
.nf
|
114
114
|
|
115
|
-
|
115
|
+
require \'ripl\'
|
116
|
+
|
117
|
+
# To try place in ~/\.riplrc
|
116
118
|
module Ripl
|
117
119
|
module RedError
|
118
120
|
def format_error(error)
|
@@ -136,7 +138,7 @@ Points to consider when creating plugins:
|
|
136
138
|
When adding functionality to a method, make sure to call \fBsuper\fR to preserve existing functionality\.
|
137
139
|
.
|
138
140
|
.IP "\(bu" 4
|
139
|
-
When replacing functionality for a method, make sure the method\'s expectations are met i\.e\. setting a specific instance variable\. Failure to do so
|
141
|
+
When replacing functionality for a method, make sure the method\'s expectations are met i\.e\. setting a specific instance variable or calling certain methods\. Failure to do so can \fBbreak\fR ripl for you and anyone else who uses your plugin!
|
140
142
|
.
|
141
143
|
.IP "\(bu" 4
|
142
144
|
Plugins can setup and teardown anything around a shell by extending Shell#before_loop and Shell#after_loop:
|
@@ -150,14 +152,12 @@ module Ripl::MyPlugin
|
|
150
152
|
|
151
153
|
def before_loop
|
152
154
|
super
|
153
|
-
|
155
|
+
# Open file, open connection \.\.\.
|
154
156
|
end
|
155
157
|
|
156
158
|
def after_loop
|
157
159
|
super
|
158
|
-
# Write to
|
159
|
-
# close a connection
|
160
|
-
# \.\.\.
|
160
|
+
# Write to file, close a connection \.\.\.
|
161
161
|
end
|
162
162
|
.
|
163
163
|
.fi
|
@@ -168,7 +168,7 @@ end
|
|
168
168
|
end
|
169
169
|
.
|
170
170
|
.IP "\(bu" 4
|
171
|
-
To add configuration for a plugin, add a key to Ripl\.config that matches the underscored version of the plugin name i\.e\. Ripl::RedError \-> Ripl\.config[:red_error]\. To set a default config value,
|
171
|
+
To add configuration for a plugin, add a key to Ripl\.config that matches the underscored version of the plugin name i\.e\. Ripl::RedError \-> Ripl\.config[:red_error]\. To set a default config value, just set it after including the plugin into Ripl::Shell\.
|
172
172
|
.
|
173
173
|
.IP "\(bu" 4
|
174
174
|
For more examples of plugins, see gems I\'ve made that start with \'ripl\-\'\.
|
data/man/ripl.1.ronn
CHANGED
@@ -84,7 +84,9 @@ be required in ~/.irbrc.
|
|
84
84
|
|
85
85
|
For an example shell plugin, let's color error messages red:
|
86
86
|
|
87
|
-
|
87
|
+
require 'ripl'
|
88
|
+
|
89
|
+
# To try place in ~/.riplrc
|
88
90
|
module Ripl
|
89
91
|
module RedError
|
90
92
|
def format_error(error)
|
@@ -102,28 +104,26 @@ Points to consider when creating plugins:
|
|
102
104
|
* When adding functionality to a method, make sure to call `super` to preserve existing functionality.
|
103
105
|
|
104
106
|
* When replacing functionality for a method, make sure the method's expectations are met i.e.
|
105
|
-
setting a specific instance variable. Failure to do so
|
106
|
-
who uses your plugin!
|
107
|
+
setting a specific instance variable or calling certain methods. Failure to do so can `break` ripl
|
108
|
+
for you and anyone else who uses your plugin!
|
107
109
|
|
108
110
|
* Plugins can setup and teardown anything around a shell by extending Shell#before_loop and Shell#after_loop:
|
109
111
|
|
110
112
|
module Ripl::MyPlugin
|
111
113
|
def before_loop
|
112
114
|
super
|
113
|
-
|
115
|
+
# Open file, open connection ...
|
114
116
|
end
|
115
117
|
|
116
118
|
def after_loop
|
117
119
|
super
|
118
|
-
# Write to
|
119
|
-
# close a connection
|
120
|
-
# ...
|
120
|
+
# Write to file, close a connection ...
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
* To add configuration for a plugin, add a key to Ripl.config that matches the underscored version
|
125
|
-
of the plugin name i.e. Ripl::RedError -> Ripl.config[:red_error]. To set a default config value,
|
126
|
-
the
|
125
|
+
of the plugin name i.e. Ripl::RedError -> Ripl.config[:red_error]. To set a default config value, just set it
|
126
|
+
after including the plugin into Ripl::Shell.
|
127
127
|
|
128
128
|
* For more examples of plugins, see gems I've made that start with 'ripl-'.
|
129
129
|
|
data/test/runner_test.rb
CHANGED
@@ -10,18 +10,18 @@ describe "Runner" do
|
|
10
10
|
Ripl.start
|
11
11
|
end
|
12
12
|
|
13
|
-
it "sets a shell's
|
13
|
+
it "sets a shell's variables" do
|
14
14
|
mock_riplrc
|
15
15
|
mock(Shell).create(anything) {|e| shell = Shell.new(e); mock(shell).loop; shell }
|
16
|
-
Ripl.start(:
|
17
|
-
Ripl.shell.
|
16
|
+
Ripl.start(:name=>'shh')
|
17
|
+
Ripl.shell.name.should == 'shh'
|
18
18
|
end
|
19
19
|
|
20
|
-
it "overrides
|
21
|
-
mock_riplrc { Ripl.config[:
|
20
|
+
it "overrides config set in riplrc" do
|
21
|
+
mock_riplrc { Ripl.config[:name] = 'blah' }
|
22
22
|
mock(Shell).create(anything) {|e| shell = Shell.new(e); mock(shell).loop; shell }
|
23
|
-
Ripl.start(:
|
24
|
-
Ripl.shell.
|
23
|
+
Ripl.start(:name=>'dude')
|
24
|
+
Ripl.shell.name.should == 'dude'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,11 +29,11 @@ describe "Runner" do
|
|
29
29
|
describe "riplrc" do
|
30
30
|
before { reset_ripl }
|
31
31
|
|
32
|
-
it "sets
|
32
|
+
it "sets config" do
|
33
33
|
mock_riplrc { Ripl.config[:blah] = true }
|
34
34
|
mock(Shell).create(anything) {|e| shell = Shell.new(e); mock(shell).loop; shell }
|
35
35
|
Runner.run([])
|
36
|
-
Ripl.
|
36
|
+
Ripl.config[:blah].should == true
|
37
37
|
end
|
38
38
|
|
39
39
|
it "catches and prints error" do
|
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: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
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-15 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|