ripl 0.2.3 → 0.2.4
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/CHANGELOG.rdoc +5 -0
- data/README.rdoc +1 -0
- data/lib/ripl.rb +1 -0
- data/lib/ripl/completion.rb +2 -2
- data/lib/ripl/history.rb +2 -1
- data/lib/ripl/shell.rb +29 -22
- data/lib/ripl/version.rb +1 -1
- data/man/ripl.1 +31 -0
- data/man/ripl.1.html +278 -0
- data/man/ripl.1.ronn +21 -5
- data/test/runner_test.rb +1 -0
- data/test/shell_test.rb +27 -0
- metadata +5 -4
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -67,6 +67,7 @@ modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:
|
|
67
67
|
* Customizable completion and completion of method arguments (from bond)
|
68
68
|
* Easy to create custom shells for gems and apps i.e. Ripl.start
|
69
69
|
* Easy to create and invoke ripl commands
|
70
|
+
* Create console commands in a simple, modular way
|
70
71
|
* ~/.irbrc errors caught
|
71
72
|
* Different from irb
|
72
73
|
* No multi-line evaluation by default (there is a plugin. See Available Plugins below).
|
data/lib/ripl.rb
CHANGED
data/lib/ripl/completion.rb
CHANGED
@@ -3,8 +3,8 @@ require 'bond'
|
|
3
3
|
module Ripl::Completion
|
4
4
|
def before_loop
|
5
5
|
super
|
6
|
-
|
7
|
-
Bond.restart((config[:completion] || {}).merge(options))
|
6
|
+
Bond.restart config[:completion]
|
8
7
|
end
|
9
8
|
end
|
10
9
|
Ripl::Shell.send :include, Ripl::Completion
|
10
|
+
(Ripl.config[:completion] ||= {})[:eval_binding] = lambda { Ripl.shell.binding }
|
data/lib/ripl/history.rb
CHANGED
@@ -10,7 +10,7 @@ module Ripl::History
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def before_loop
|
13
|
-
|
13
|
+
@history = []
|
14
14
|
super
|
15
15
|
at_exit { write_history }
|
16
16
|
File.exists?(history_file) &&
|
@@ -22,3 +22,4 @@ module Ripl::History
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
Ripl::Shell.send :include, Ripl::History
|
25
|
+
Ripl.config[:history] = '~/.irb_history'
|
data/lib/ripl/shell.rb
CHANGED
@@ -10,7 +10,7 @@ class Ripl::Shell
|
|
10
10
|
new(options)
|
11
11
|
end
|
12
12
|
|
13
|
-
attr_accessor :line, :binding, :
|
13
|
+
attr_accessor :line, :binding, :result, :name
|
14
14
|
def initialize(options={})
|
15
15
|
options = OPTIONS.merge options
|
16
16
|
@name, @binding = options.values_at(:name, :binding)
|
@@ -27,31 +27,38 @@ class Ripl::Shell
|
|
27
27
|
|
28
28
|
def config; Ripl.config; end
|
29
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
|
-
|
50
30
|
module API
|
31
|
+
attr_accessor :prompt, :result_prompt
|
51
32
|
# Sets up shell before looping by loading ~/.irbrc. Can be extended to
|
52
33
|
# initialize plugins and their instance variables.
|
53
34
|
def before_loop
|
54
35
|
Ripl::Runner.load_rc(@irbrc) if @irbrc
|
36
|
+
add_commands(loop_eval("self"))
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_commands(obj)
|
40
|
+
![Symbol, Fixnum].include?(obj.class) ? obj.extend(Ripl::Commands) :
|
41
|
+
obj.class.send(:include, Ripl::Commands)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Runs through one loop iteration: gets input, evals and prints result
|
45
|
+
def loop_once
|
46
|
+
@error_raised = nil
|
47
|
+
@input = get_input
|
48
|
+
throw(:ripl_exit) if !@input || @input == 'exit'
|
49
|
+
eval_input(@input)
|
50
|
+
print_result(@result)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Sets @result to result of evaling input and print unexpected errors
|
54
|
+
def eval_input(input)
|
55
|
+
@result = loop_eval(input)
|
56
|
+
eval("_ = Ripl.shell.result", @binding)
|
57
|
+
rescue Exception => e
|
58
|
+
@error_raised = true
|
59
|
+
print_eval_error(e)
|
60
|
+
ensure
|
61
|
+
@line += 1
|
55
62
|
end
|
56
63
|
|
57
64
|
# @return [String, nil] Prints #prompt and returns input given by user
|
@@ -89,7 +96,7 @@ class Ripl::Shell
|
|
89
96
|
|
90
97
|
# @return [String] Formats result using result_prompt
|
91
98
|
def format_result(result)
|
92
|
-
|
99
|
+
result_prompt + result.inspect
|
93
100
|
end
|
94
101
|
|
95
102
|
# Called after shell finishes looping.
|
data/lib/ripl/version.rb
CHANGED
data/man/ripl.1
CHANGED
@@ -171,6 +171,37 @@ end
|
|
171
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
|
+
To add console commands for a plugin, make them methods in a module and include the module into Ripl::Commands\. For example:
|
175
|
+
.
|
176
|
+
.IP
|
177
|
+
module Ripl::SuperHistory
|
178
|
+
.
|
179
|
+
.IP "" 4
|
180
|
+
.
|
181
|
+
.nf
|
182
|
+
|
183
|
+
# plugin hooks into history
|
184
|
+
# then defines command
|
185
|
+
module Commands
|
186
|
+
def history
|
187
|
+
# \.\.\.
|
188
|
+
end
|
189
|
+
end
|
190
|
+
.
|
191
|
+
.fi
|
192
|
+
.
|
193
|
+
.IP "" 0
|
194
|
+
.
|
195
|
+
.IP
|
196
|
+
end
|
197
|
+
.
|
198
|
+
.IP
|
199
|
+
Ripl::Commands\.send :include, Ripl::SuperHistory::Commands
|
200
|
+
.
|
201
|
+
.IP
|
202
|
+
>> history # use command in ripl
|
203
|
+
.
|
204
|
+
.IP "\(bu" 4
|
174
205
|
For more examples of plugins, see gems I\'ve made that start with \'ripl\-\'\.
|
175
206
|
.
|
176
207
|
.IP "" 0
|
data/man/ripl.1.html
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv='content-type' value='text/html;charset=utf8'>
|
5
|
+
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
|
6
|
+
<title>ripl(1) - Ruby Interactive Print Loop - A light, modular alternative to irb</title>
|
7
|
+
<style type='text/css' media='all'>
|
8
|
+
/* style: man */
|
9
|
+
body#manpage {margin:0}
|
10
|
+
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
|
11
|
+
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
|
12
|
+
.mp h2 {margin:10px 0 0 0}
|
13
|
+
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
|
14
|
+
.mp h3 {margin:0 0 0 4ex}
|
15
|
+
.mp dt {margin:0;clear:left}
|
16
|
+
.mp dt.flush {float:left;width:8ex}
|
17
|
+
.mp dd {margin:0 0 0 9ex}
|
18
|
+
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
|
19
|
+
.mp pre {margin-bottom:20px}
|
20
|
+
.mp pre+h2,.mp pre+h3 {margin-top:22px}
|
21
|
+
.mp h2+pre,.mp h3+pre {margin-top:5px}
|
22
|
+
.mp img {display:block;margin:auto}
|
23
|
+
.mp h1.man-title {display:none}
|
24
|
+
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
|
25
|
+
.mp h2 {font-size:16px;line-height:1.25}
|
26
|
+
.mp h1 {font-size:20px;line-height:2}
|
27
|
+
.mp {text-align:justify;background:#fff}
|
28
|
+
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
|
29
|
+
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
|
30
|
+
.mp u {text-decoration:underline}
|
31
|
+
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
|
32
|
+
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
|
33
|
+
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
|
34
|
+
.mp b.man-ref {font-weight:normal;color:#434241}
|
35
|
+
.mp pre {padding:0 4ex}
|
36
|
+
.mp pre code {font-weight:normal;color:#434241}
|
37
|
+
.mp h2+pre,h3+pre {padding-left:0}
|
38
|
+
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
|
39
|
+
ol.man-decor {width:100%}
|
40
|
+
ol.man-decor li.tl {text-align:left}
|
41
|
+
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
|
42
|
+
ol.man-decor li.tr {text-align:right;float:right}
|
43
|
+
</style>
|
44
|
+
</head>
|
45
|
+
<!--
|
46
|
+
The following styles are deprecated and will be removed at some point:
|
47
|
+
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
|
48
|
+
|
49
|
+
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
|
50
|
+
.man-navigation should be used instead.
|
51
|
+
-->
|
52
|
+
<body id='manpage'>
|
53
|
+
<div class='mp' id='man'>
|
54
|
+
|
55
|
+
<div class='man-navigation' style='display:none'>
|
56
|
+
<a href="#NAME">NAME</a>
|
57
|
+
<a href="#SYNOPSIS">SYNOPSIS</a>
|
58
|
+
<a href="#DESCRIPTION">DESCRIPTION</a>
|
59
|
+
<a href="#COMING-FROM-IRB">COMING FROM IRB</a>
|
60
|
+
<a href="#CONFIGURATION">CONFIGURATION</a>
|
61
|
+
<a href="#PLUGINS">PLUGINS</a>
|
62
|
+
<a href="#CREATE-PLUGINS">CREATE PLUGINS</a>
|
63
|
+
<a href="#CREATE-CUSTOM-SHELLS">CREATE CUSTOM SHELLS</a>
|
64
|
+
<a href="#COMMANDS">COMMANDS</a>
|
65
|
+
<a href="#BUGS">BUGS</a>
|
66
|
+
<a href="#COPYRIGHT">COPYRIGHT</a>
|
67
|
+
<a href="#SEE-ALSO">SEE ALSO</a>
|
68
|
+
</div>
|
69
|
+
|
70
|
+
<ol class='man-decor man-head man head'>
|
71
|
+
<li class='tl'>ripl(1)</li>
|
72
|
+
<li class='tc'>Ripl Manual</li>
|
73
|
+
<li class='tr'>ripl(1)</li>
|
74
|
+
</ol>
|
75
|
+
|
76
|
+
<h2 id="NAME">NAME</h2>
|
77
|
+
<p class="man-name">
|
78
|
+
<code>ripl</code> - <span class="man-whatis">Ruby Interactive Print Loop - A light, modular alternative to irb</span>
|
79
|
+
</p>
|
80
|
+
|
81
|
+
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
82
|
+
|
83
|
+
<pre><code>ripl [-r|--require] [-I] [-f] [-d] [-h|--help] [-v|--version] COMMAND [ARGS]
|
84
|
+
</code></pre>
|
85
|
+
|
86
|
+
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
87
|
+
|
88
|
+
<p>ripl is a light, modular alternative to irb. Like irb, it loads ~/.irbrc, has autocompletion and
|
89
|
+
keeps history in ~/.irb_history. Unlike irb, it is highly customizable via plugins and supports
|
90
|
+
commands. This customizability makes it easy to build custom shells (i.e. for a gem or application)
|
91
|
+
and complex shells (i.e. for the web).</p>
|
92
|
+
|
93
|
+
<h2 id="COMING-FROM-IRB">COMING FROM IRB</h2>
|
94
|
+
|
95
|
+
<p>When first trying ripl, you may experience errors in your ~/.irbrc due to an irb-specific
|
96
|
+
configuration. In order to have ripl and irb coexist peacefully, you should silence these errors.
|
97
|
+
To silence them without touching your ~/.irbrc, install the ripl-irb gem. This ripl plugin fakes
|
98
|
+
irb's existence, effectively ignoring irb-specific configuration. Otherwise, if you don't mind
|
99
|
+
modifying ~/.irbrc, wrap your irb-specific configuration in a block as follow:</p>
|
100
|
+
|
101
|
+
<pre><code>if defined? IRB
|
102
|
+
IRB.conf[:BLAH] = 'blah'
|
103
|
+
# ...
|
104
|
+
end
|
105
|
+
</code></pre>
|
106
|
+
|
107
|
+
<h2 id="CONFIGURATION">CONFIGURATION</h2>
|
108
|
+
|
109
|
+
<p>All ripl shells load the ruby file ~/.riplrc if it exists. In this file, plugins are required and
|
110
|
+
configuration options are set. To configure ripl and its plugins, use Ripl.config. By default,
|
111
|
+
Ripl.config is a hash with the following keys:</p>
|
112
|
+
|
113
|
+
<dl>
|
114
|
+
<dt><code>:binding</code></dt><dd><p>Binding to use for eval(). Default is TOPLEVEL_BINDING.</p></dd>
|
115
|
+
<dt><code>:completion</code></dt><dd><p>A hash that configures completion via Bond.start. See bond for more details.</p></dd>
|
116
|
+
<dt><code>:history</code></dt><dd><p>A file used to store input history. Default is '~/.irb_history'.</p></dd>
|
117
|
+
<dt class="flush"><code>:irbrc</code></dt><dd><p>A ruby file to load at startup or false to not load anything. Default is '~/.irbrc'.</p></dd>
|
118
|
+
<dt class="flush"><code>:name</code></dt><dd><p>Name of the shell. Default is 'ripl'.</p></dd>
|
119
|
+
<dt class="flush"><code>:prompt</code></dt><dd><p>A string or lambda to generate string that prompts user for input. Default is '>> '.</p></dd>
|
120
|
+
<dt><code>:readline</code></dt><dd><p>A boolean to enable Readline. Default is true.</p></dd>
|
121
|
+
<dt><code>:result_prompt</code></dt><dd><p>A string that prefixes the result of an eval. Default is '=> '.</p></dd>
|
122
|
+
</dl>
|
123
|
+
|
124
|
+
|
125
|
+
<p>Plugins can optionally provide their own config key(s) for use here. It is strongly recommended that
|
126
|
+
a plugin start with an underscored version of its name i.e. Ripl::ColorError -> Ripl.config[:color_error].</p>
|
127
|
+
|
128
|
+
<p>An example ~/.riplrc:</p>
|
129
|
+
|
130
|
+
<pre><code> require 'ripl/multi_line'
|
131
|
+
require 'ripl/color_error'
|
132
|
+
Ripl.config[:color_error] = :blue
|
133
|
+
</code></pre>
|
134
|
+
|
135
|
+
<h2 id="PLUGINS">PLUGINS</h2>
|
136
|
+
|
137
|
+
<p>A ripl plugin is a module that is included into Ripl::Shell or Ripl::Runner. Being simply modules,
|
138
|
+
they can be packaged as gems and reused across shells as needed. ripl highly encourages plugins by
|
139
|
+
loading them as early as possible and allowing them to extend most of ripl's functionality. As
|
140
|
+
mentioned in the <code>CONFIGURATION</code> section, a plugin can be configured via Ripl.config.</p>
|
141
|
+
|
142
|
+
<p>To always use a plugin, require it in ~/.riplrc. To sometimes use it, require it from
|
143
|
+
the commandline:</p>
|
144
|
+
|
145
|
+
<pre><code>$ ripl -rripl/multi_line
|
146
|
+
</code></pre>
|
147
|
+
|
148
|
+
<p>Plugins can also be required in the console but it is not recommended since plugins can depend on
|
149
|
+
initialization that occurs before the console is started. For this same reason, plugins should not
|
150
|
+
be required in ~/.irbrc.</p>
|
151
|
+
|
152
|
+
<h2 id="CREATE-PLUGINS">CREATE PLUGINS</h2>
|
153
|
+
|
154
|
+
<p>For an example shell plugin, let's color error messages red:</p>
|
155
|
+
|
156
|
+
<pre><code>require 'ripl'
|
157
|
+
|
158
|
+
# To try place in ~/.riplrc
|
159
|
+
module Ripl
|
160
|
+
module RedError
|
161
|
+
def format_error(error)
|
162
|
+
"\e[31m#{super}\e[m"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
Ripl::Shell.send :include, Ripl::RedError
|
167
|
+
</code></pre>
|
168
|
+
|
169
|
+
<p>Note this plugin extends format_error() by invoking the original format_error() with super. To see
|
170
|
+
what methods are available for extension, see Ripl::Shell::API and Ripl::Runner::API.</p>
|
171
|
+
|
172
|
+
<p>Points to consider when creating plugins:</p>
|
173
|
+
|
174
|
+
<ul>
|
175
|
+
<li><p>When adding functionality to a method, make sure to call <code>super</code> to preserve existing functionality.</p></li>
|
176
|
+
<li><p>When replacing functionality for a method, make sure the method's expectations are met i.e.
|
177
|
+
setting a specific instance variable or calling certain methods. Failure to do so can <code>break</code> ripl
|
178
|
+
for you and anyone else who uses your plugin!</p></li>
|
179
|
+
<li><p>Plugins can setup and teardown anything around a shell by extending Shell#before_loop and Shell#after_loop:</p>
|
180
|
+
|
181
|
+
<p> module Ripl::MyPlugin</p>
|
182
|
+
|
183
|
+
<pre><code>def before_loop
|
184
|
+
super
|
185
|
+
# Open file, open connection ...
|
186
|
+
end
|
187
|
+
|
188
|
+
def after_loop
|
189
|
+
super
|
190
|
+
# Write to file, close a connection ...
|
191
|
+
end
|
192
|
+
</code></pre>
|
193
|
+
|
194
|
+
<p> end</p></li>
|
195
|
+
<li><p>To add configuration for a plugin, add a key to Ripl.config that matches the underscored version
|
196
|
+
of the plugin name i.e. Ripl::RedError -> Ripl.config[:red_error]. To set a default config value, just set it
|
197
|
+
after including the plugin into Ripl::Shell.</p></li>
|
198
|
+
<li><p>To add console commands for a plugin, make them methods in a module and include the module into Ripl::Commands. For example:</p>
|
199
|
+
|
200
|
+
<p> module Ripl::SuperHistory</p>
|
201
|
+
|
202
|
+
<pre><code># plugin hooks into history
|
203
|
+
# then defines command
|
204
|
+
module Commands
|
205
|
+
def history
|
206
|
+
# ...
|
207
|
+
end
|
208
|
+
end
|
209
|
+
</code></pre>
|
210
|
+
|
211
|
+
<p> end</p>
|
212
|
+
|
213
|
+
<p> Ripl::Commands.send :include, Ripl::SuperHistory::Commands</p>
|
214
|
+
|
215
|
+
<p> >> history # use command in ripl</p></li>
|
216
|
+
<li><p>For more examples of plugins, see gems I've made that start with 'ripl-'.</p></li>
|
217
|
+
</ul>
|
218
|
+
|
219
|
+
|
220
|
+
<h2 id="CREATE-CUSTOM-SHELLS">CREATE CUSTOM SHELLS</h2>
|
221
|
+
|
222
|
+
<p>Creating and starting a custom shell is as simple as:</p>
|
223
|
+
|
224
|
+
<pre><code>require 'ripl'
|
225
|
+
# Define plugins, load files, etc...
|
226
|
+
Ripl.start
|
227
|
+
</code></pre>
|
228
|
+
|
229
|
+
<p>Ripl.start takes the same config keys mentioned in the <code>CONFIGURATION</code> section. For example if you wanted to
|
230
|
+
start on a specific binding:</p>
|
231
|
+
|
232
|
+
<pre><code>Ripl.start :binding => MyClass.send(:binding)
|
233
|
+
</code></pre>
|
234
|
+
|
235
|
+
<p>Also, since all shells load ~/.riplrc, Ripl.start can be used to override undesirable global
|
236
|
+
configuration for a custom shell.</p>
|
237
|
+
|
238
|
+
<h2 id="COMMANDS">COMMANDS</h2>
|
239
|
+
|
240
|
+
<p>A ripl command is a command passed to ripl that loads a custom shell. It's a convenient way to
|
241
|
+
package and invoke custom shells. A ripl command can take standard ripl options as long as they are
|
242
|
+
before the command:</p>
|
243
|
+
|
244
|
+
<pre><code># Load rails console without ~/.irbrc
|
245
|
+
$ ripl -f rails
|
246
|
+
|
247
|
+
# Load rails console with debugger
|
248
|
+
$ ripl -rrdebug rails
|
249
|
+
</code></pre>
|
250
|
+
|
251
|
+
<p>To create a ripl command, create an executable in the format ripl-command and make sure it's in your
|
252
|
+
shell's $PATH. For example, the file 'ripl-my_gem' would be invoked with 'ripl my_gem'. Any
|
253
|
+
arguments to a ripl command can be parsed as the ripl command pleases i.e. into options and
|
254
|
+
arguments. For an example command, see <a href="http://github.com/cldwalker/ripl-rails">ripl-rails</a>.</p>
|
255
|
+
|
256
|
+
<h2 id="BUGS">BUGS</h2>
|
257
|
+
|
258
|
+
<p>Please report bugs at <a href="http://github.com/cldwalker/ripl/issues" data-bare-link="true">http://github.com/cldwalker/ripl/issues</a>.</p>
|
259
|
+
|
260
|
+
<h2 id="COPYRIGHT">COPYRIGHT</h2>
|
261
|
+
|
262
|
+
<p><code>ripl</code> is Copyright (C) 2010 Gabriel Horner</p>
|
263
|
+
|
264
|
+
<h2 id="SEE-ALSO">SEE ALSO</h2>
|
265
|
+
|
266
|
+
<p><a href="http://github.com/cldwalker/ripl" data-bare-link="true">http://github.com/cldwalker/ripl</a>, <a href="http://github.com/cldwalker/bond" data-bare-link="true">http://github.com/cldwalker/bond</a>, <a href="http://github.com/cldwalker/nirvana" data-bare-link="true">http://github.com/cldwalker/nirvana</a>,
|
267
|
+
<a href="http://github.com/cldwalker/ripl-irb" data-bare-link="true">http://github.com/cldwalker/ripl-irb</a>, <a href="http://github.com/cldwalker/ripl-rails" data-bare-link="true">http://github.com/cldwalker/ripl-rails</a>, <a href="http://github.com/janlelis/multi_line" data-bare-link="true">http://github.com/janlelis/multi_line</a></p>
|
268
|
+
|
269
|
+
|
270
|
+
<ol class='man-decor man-foot man foot'>
|
271
|
+
<li class='tl'>CLDWALKER</li>
|
272
|
+
<li class='tc'>November 2010</li>
|
273
|
+
<li class='tr'>ripl(1)</li>
|
274
|
+
</ol>
|
275
|
+
|
276
|
+
</div>
|
277
|
+
</body>
|
278
|
+
</html>
|
data/man/ripl.1.ronn
CHANGED
@@ -104,8 +104,8 @@ Points to consider when creating plugins:
|
|
104
104
|
* When adding functionality to a method, make sure to call `super` to preserve existing functionality.
|
105
105
|
|
106
106
|
* When replacing functionality for a method, make sure the method's expectations are met i.e.
|
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
|
+
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!
|
109
109
|
|
110
110
|
* Plugins can setup and teardown anything around a shell by extending Shell#before_loop and Shell#after_loop:
|
111
111
|
|
@@ -122,8 +122,24 @@ for you and anyone else who uses your plugin!
|
|
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, just set it
|
126
|
-
after including the plugin into Ripl::Shell.
|
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
|
+
|
128
|
+
* To add console commands for a plugin, make them methods in a module and include the module into Ripl::Commands. For example:
|
129
|
+
|
130
|
+
module Ripl::SuperHistory
|
131
|
+
# plugin hooks into history
|
132
|
+
# then defines command
|
133
|
+
module Commands
|
134
|
+
def history
|
135
|
+
# ...
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
Ripl::Commands.send :include, Ripl::SuperHistory::Commands
|
141
|
+
|
142
|
+
\>\> history # use command in ripl
|
127
143
|
|
128
144
|
* For more examples of plugins, see gems I've made that start with 'ripl-'.
|
129
145
|
|
@@ -162,7 +178,7 @@ arguments. For an example command, see [ripl-rails](http://github.com/cldwalker/
|
|
162
178
|
|
163
179
|
## BUGS
|
164
180
|
|
165
|
-
Please report bugs at
|
181
|
+
Please report bugs at <http://github.com/cldwalker/ripl/issues>.
|
166
182
|
|
167
183
|
## COPYRIGHT
|
168
184
|
|
data/test/runner_test.rb
CHANGED
data/test/shell_test.rb
CHANGED
@@ -32,6 +32,22 @@ describe "Shell" do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
describe "#before_loop" do
|
36
|
+
before_all { Ripl::Commands.send(:define_method, :ping) { 'pong' } }
|
37
|
+
it "adds commands to main from Commands" do
|
38
|
+
stub(Ripl::Runner).load_rc
|
39
|
+
Ripl.shell.before_loop
|
40
|
+
Ripl.shell.loop_eval("ping").should == 'pong'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "adds commands to fixnum from Commands" do
|
44
|
+
stub(Ripl::Runner).load_rc
|
45
|
+
Ripl.shell.binding = 1.send(:binding)
|
46
|
+
Ripl.shell.before_loop
|
47
|
+
Ripl.shell.loop_eval("ping").should == 'pong'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
35
51
|
describe "#eval_input" do
|
36
52
|
before { @line = shell.line; shell.eval_input("10 ** 2") }
|
37
53
|
|
@@ -69,4 +85,15 @@ describe "Shell" do
|
|
69
85
|
end
|
70
86
|
end
|
71
87
|
end
|
88
|
+
|
89
|
+
describe "API#" do
|
90
|
+
Shell::API.instance_methods.delete_if {|e| e[/=$/]}.each do |meth|
|
91
|
+
it "#{meth} is accessible to plugins" do
|
92
|
+
mod = Object.const_set "Ping_#{meth}", Module.new
|
93
|
+
mod.send(:define_method, meth) { "pong_#{meth}" }
|
94
|
+
Shell.send :include, mod
|
95
|
+
shell.send(meth).should == "pong_#{meth}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
72
99
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
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-18 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- .gemspec
|
111
111
|
- man/ripl.1
|
112
|
+
- man/ripl.1.html
|
112
113
|
- man/ripl.1.ronn
|
113
114
|
has_rdoc: true
|
114
115
|
homepage: http://github.com/cldwlaker/ripl
|