rib 0.1.0 → 0.9.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.
Files changed (60) hide show
  1. data/.gitignore +0 -4
  2. data/CHANGES.md +6 -0
  3. data/README +107 -113
  4. data/README.md +107 -113
  5. data/Rakefile +5 -3
  6. data/TODO.md +6 -0
  7. data/bin/rib-all +5 -0
  8. data/bin/rib-auto +9 -0
  9. data/bin/rib-min +5 -0
  10. data/bin/rib-rails +9 -0
  11. data/bin/rib-ramaze +9 -0
  12. data/lib/rib.rb +70 -6
  13. data/lib/rib/all.rb +0 -1
  14. data/lib/rib/api.rb +60 -64
  15. data/lib/rib/app/auto.rb +25 -0
  16. data/lib/rib/app/rails.rb +41 -0
  17. data/lib/rib/app/ramaze.rb +25 -0
  18. data/lib/rib/config.rb +3 -0
  19. data/lib/rib/core.rb +13 -1
  20. data/lib/rib/core/completion.rb +15 -3
  21. data/lib/rib/core/history.rb +56 -0
  22. data/lib/rib/core/multiline.rb +104 -0
  23. data/lib/rib/core/readline.rb +3 -1
  24. data/lib/rib/core/squeeze_history.rb +45 -0
  25. data/lib/rib/core/strip_backtrace.rb +45 -0
  26. data/lib/rib/core/underscore.rb +17 -8
  27. data/lib/rib/debug.rb +2 -1
  28. data/lib/rib/dep/hirb.rb +24 -0
  29. data/lib/rib/more.rb +4 -3
  30. data/lib/rib/more/anchor.rb +85 -0
  31. data/lib/rib/more/color.rb +44 -43
  32. data/lib/rib/{zore → more}/edit.rb +3 -3
  33. data/lib/rib/more/multiline_history.rb +24 -12
  34. data/lib/rib/more/multiline_history_file.rb +7 -3
  35. data/lib/rib/plugin.rb +2 -4
  36. data/lib/rib/runner.rb +84 -49
  37. data/lib/rib/shell.rb +4 -2
  38. data/lib/rib/test.rb +55 -2
  39. data/lib/rib/test/multiline.rb +140 -0
  40. data/lib/rib/version.rb +1 -1
  41. data/rib.gemspec +54 -22
  42. data/screenshot.png +0 -0
  43. data/task/gemgem.rb +3 -1
  44. data/test/core/{test_history_file.rb → test_history.rb} +29 -19
  45. data/test/core/test_multiline.rb +22 -0
  46. data/test/core/test_readline.rb +13 -8
  47. data/test/{more → core}/test_squeeze_history.rb +24 -18
  48. data/test/core/test_underscore.rb +32 -21
  49. data/test/more/test_multiline_history.rb +42 -0
  50. data/test/test_shell.rb +13 -8
  51. metadata +72 -27
  52. data/2011-02-28.md +0 -203
  53. data/CHANGES +0 -86
  54. data/TODO +0 -6
  55. data/lib/rib/core/history_file.rb +0 -38
  56. data/lib/rib/more/multiline.rb +0 -77
  57. data/lib/rib/more/squeeze_history.rb +0 -37
  58. data/lib/rib/more/strip_backtrace.rb +0 -43
  59. data/lib/rib/zore.rb +0 -3
  60. data/lib/rib/zore/anchor.rb +0 -69
data/2011-02-28.md DELETED
@@ -1,203 +0,0 @@
1
- [original text](http://blogger.godfat.org/2011/02/ripl-rc-1-ripl-irb-replacement.html)
2
-
3
- # ripl, an irb replacement
4
-
5
- <p></p><a href="http://www.urbandictionary.com/define.php?term=TL%3BDR">TL;DR</a>: see the <a href="#comparison">comparison table/list</a> on
6
- the bottom of this post. Still TL;DR?
7
- <pre><code>&gt; gem install ripl
8
- &gt; ripl rc</code></pre>
9
- <img src="https://github.com/godfat/ripl-rc/raw/ripl-rc-0.1.3/screenshot.png"/>
10
-
11
- Use it in rails console?
12
- <pre><code>&gt; gem install ripl-rails
13
- &gt; ripl rc rails</code></pre>
14
-
15
- # ripl
16
-
17
- Days ago when I was using <a href="https://github.com/banister/pry">pry</a> to debug heroku-scaler,
18
- (which is a <a href="https://github.com/Ramaze/ramaze">ramaze</a> and <a href="https://github.com/igrigorik/em-http-request">em-http-request</a> application),
19
- I wanted to make pry use irb history to easy debugging,
20
- and then I found it was talking about something like
21
- pry is not an irb replacement, to find an irb replacement,
22
- see <a href="https://github.com/cldwalker/ripl">ripl</a>. That's where I started playing around with ripl.
23
-
24
- At first, I didn't think I need an replacement for irb,
25
- because it worked for me. But as always, we don't know
26
- if we need a better tool until we're really using a better
27
- tool. ripl is this kind of story for me, and so do <a href="https://github.com/lsegal/yard">yard</a> to
28
- <a href="https://github.com/rdoc/rdoc">rdoc</a> and so on so forth. Interestingly, this is not always
29
- true for all tools. For example, I like <a href="https://github.com/jimweirich/rake">rake</a> better than
30
- <a href="https://github.com/wycats/thor">thor</a> (though I didn't really try thor), and didn't really
31
- need the power of <a href="http://www.kuwata-lab.com/erubis/">erubis</a> over erb.
32
-
33
- One can think that, using thor/erubis might force others
34
- to do the same (though erubis could be used as a drop-in
35
- replacement for erb), but irb/ripl is just a personal tool
36
- instead of really a library that once you used it in the
37
- application, all developers would be forced to use or test
38
- against it, too. Just like a text editor. Personal taste only..
39
-
40
- Back to topic...
41
-
42
- So what would we benefit from switching irb to ripl? If
43
- we're only using the core functionality of ripl, then not
44
- even talking about gains, but we'll lose some features
45
- that irb provides but ripl doesn't. What good is, according
46
- to the <a href="https://github.com/cldwalker/ripl/blob/v0.3.2/README.rdoc">README</a> of ripl, the code size was about ~270
47
- lines vs 5,000+ lines, so we can expect that ripl is a lot
48
- easier to extend and customize, and this is also a fact.
49
-
50
- ripl is designed to be extended and customized from the
51
- beginning, and since the code is very modular and
52
- lightweight, it's very easy to replicate irb's behavior
53
- and features that are missing in ripl. You can take a look
54
- at ripl-irb. It might grow to be fat after installing many
55
- plugins and extensions, but I guess it will never reach
56
- the size of irb, since irb *has its own ruby parser*...
57
- <a href="https://github.com/janlelis/ripl-multi_line">ripl-multi_line</a> uses a trick that catches syntax error
58
- exception to achieve multiline support. This might be
59
- tricky because it depends on the error message coming
60
- from syntax error; however irb's own ruby parser might
61
- not be accurate as well... as long as it's not using ruby's
62
- own parser.
63
-
64
- At first I was trying to add some simple patches with only
65
- a few of lines to the core of ripl to make it better, but the
66
- author only accepted my bug fix patches instead of features
67
- patches, even it's only a few of lines and I don't see why
68
- others won't want that features. Sometimes this make me
69
- feel like vim or bash, you'll definitely want some personal
70
- (might not be so personal though) config files instead of
71
- using the defaults, which is very different than GUI
72
- applications, which always try to provide the best defaults.
73
- I think both have their strength, and I don't mind as long
74
- as it could be customized to suit my flavor, and that's why
75
- I've written <a href="https://github.com/godfat/ripl-rc">ripl-rc</a>.
76
-
77
- ripl-rc is a ripl plugins collection, each of its require is a
78
- different plugin. For example:
79
- <pre><code>require 'ripl/rc/color'
80
- require 'ripl/rc/anchor'</code></pre>
81
- The first line would enable colorizing plugin, and the latter
82
- would enable pry session like plugin. The reason I do this
83
- instead of releasing ripl-color, ripl-anchor, etc., is I think
84
- it's a lot easier to maintain and install as a plugin collection,
85
- since each plugin has only a few of codes. We can take
86
- advantage of fixing plugins at the same time, too, since
87
- some plugins would work with other plugins. (e.g.
88
- ripl/rc/anchor and ripl/rc/color) It would be tedious for
89
- users and developers to release or update a bunch of new
90
- releases... I really hate rails doing that, though the code
91
- base is not the same level. It might be a must for rails
92
- somehow...
93
-
94
- Enough of rubbish, let's see the comparison.<a id="comparison"></a>
95
-
96
- # Comparison
97
-
98
- ripl has:
99
-
100
- * a lot fewer codes and is a lot easier to customize
101
- * better auto-complete (from <a href="https://github.com/cldwalker/bond">bond</a>)
102
-
103
- irb has:
104
-
105
- * multiline support (ripl uses ripl-multi_line)
106
- * subsessions and workspaces (actually I don't know
107
- what are they, never used. ripl uses <a href="https://github.com/cldwalker/ripl-commands">ripl-commands</a>)
108
-
109
- ripl-rc has, upon session ends:
110
-
111
- * <span style="color:gold">require 'ripl/rc/squeeze_history'</span>
112
-
113
- which squeezes the same input in history, both in memory
114
- and history file.
115
-
116
- * <span style="color:gold">require 'ripl/rc/mkdir_history'</span>
117
-
118
- which calls `mkdir -p` on directory which contains history
119
- file. For example, I put my irb_history in an directory
120
- might not exist before use: `~/.config/irb/irb_history`
121
-
122
- * <span style="color:gold">require 'ripl/rc/ctrld_newline'</span>
123
-
124
- ruby 1.9.2 has no this problem in irb, but 1.8 and ripl do.
125
- When hitting ctrl+d to exit ripl, it would print a newline
126
- instead of messing up with shell prompt.
127
-
128
- upon formatting output:
129
-
130
- * <span style="color:gold">require 'ripl/rc/strip_backtrace'</span>
131
-
132
- ripl prints the full backtrace upon exceptions, even the
133
- exceptions come from interactive environment, making it
134
- very verbose. This ripl plugin strips those backtrace.
135
-
136
- * <span style="color:gold">require 'ripl/rc/color'</span>
137
-
138
- There's ripl-color_result that make use of <a href="https://github.com/michaeldv/awesome_print">awesome_print</a>,
139
- <a href="http://coderay.rubychan.de/">coderay</a>, or <a href="https://github.com/janlelis/wirb">wirb</a>. The problem of awesome_print is it's too
140
- awesome and too verbose, and the problem of coderay and
141
- wirb is that they are both parser based. In ripl, this should
142
- be as simple as just print different colors upon different
143
- objects, instead of inspecting it and parsing it.
144
-
145
- ripl/rc/color just uses a hash with Class to color mapping
146
- to pick up which color should be used upon a ruby object.
147
-
148
- To customize the color schema, inspect `Ripl.config[:rc_color]`
149
-
150
- upon input:
151
-
152
- * <span style="color:gold">require 'ripl/rc/multiline'</span>
153
-
154
- I need some modification on ripl-multi_line to make prompt
155
- work better, but not sure if I can come up a good fix and
156
- try to convince the author to accept those patches. So I
157
- just bundle and maintain it on my own. If you're using
158
- ripl-rc, you could use this plugin, otherwise, keep using
159
- ripl-multi_line.
160
-
161
- * <span style="color:gold">require 'ripl/rc/eat_whites'</span>
162
-
163
- irb will just give you another prompt upon an empty input,
164
- while ripl would show you that your input is nil. I don't like
165
- this, because sometimes I'll keep hitting enter to separate
166
- between inspects. This plugin would skip inspect if the input
167
- is empty just like irb.
168
-
169
- special tool:
170
-
171
- * <span style="color:gold">require 'ripl/rc/anchor'</span>
172
-
173
- So this is my attempt to emulate pry in ripl. Instead
174
- trying to make pry support irb_history, colorizing, etc.,
175
- I think implement pry like feature in ripl is a lot easier.
176
- No need to be fancy, I just need the basic functionality.
177
-
178
- To use it, use:
179
- <pre><code>Ripl.anchor your_object_want_to_be_viewed_as_self</code></pre>
180
- or
181
- <pre><code>Ripl.anchor binding</code></pre>
182
- in your code. Other than pry ripl support, you might be
183
- interested in <a href="https://github.com/cldwalker/ripl-rails">ripl-rails</a> and <a href="https://github.com/cldwalker/ripl-hijack">ripl-hijack</a>, too.
184
-
185
- about config:
186
-
187
- * <span style="color:gold">require 'ripl/rc/noirbrc'</span>
188
-
189
- By default ripl is reading `~/.irbrc`. I don't think this
190
- is what people still using irb would want, because the
191
- configuration is totally different. This suppress that,
192
- make it only read `~/.riplrc`
193
-
194
- for lazies:
195
-
196
- * <span style="color:gold">require 'ripl/rc'</span>
197
-
198
- This requires anything above for you, and is what `ripl rc`
199
- and `ripl rc rails` shell commands did.
200
-
201
- So that's all at the moment for <a href="https://github.com/godfat/ripl-rc/tree/ripl-rc-0.1.3">ripl-rc 0.1.3</a>. Enjoy,
202
-
203
- 2010-02-28 (16:36~21:49)
data/CHANGES DELETED
@@ -1,86 +0,0 @@
1
- = ripl-rc changes history
2
-
3
- == ripl-rc 0.2.4 -- 2011-08-03
4
-
5
- * [ensure_after_loop] A plugin which would make sure after_loop is called.
6
- (Some plugins need to do cleaning up in after_loop)
7
-
8
- * [ anchor] Fixed a bug for buggy EditLine, which would raise
9
- weird exception upon calling `HISTORY == nil`.
10
- Now we use `.nil?` to lookup if it's nil or not.
11
-
12
- * [multiline_history] Fixed a bug when multiline evaluation raised an
13
- exception, it wouldn't handle the history correctly.
14
- Moving the handling to an ensure block fixed this.
15
-
16
- * [ squeeze_history] (Internal) Take the advantage of the new history API
17
-
18
- == ripl-rc 0.2.3 -- 2011-06-16
19
-
20
- Please read this for detail:
21
- http://blogger.godfat.org/2011/06/new-feature-mainly-for-anchor-in-ripl.html
22
-
23
- * [ripl-rc] Ripl.enable/disable_??? now accepts a block to ease switching.
24
- * [ debug] This plugin is simply calling Ripl.disable_anchor at the
25
- beginning, make it easier to use [anchor] to inspect a certain
26
- place under a certain condition. See the blog post for detail.
27
-
28
- == ripl-rc 0.2.2 -- 2011-06-01
29
-
30
- * [multiline_history ] fixed multiline_history
31
- * [multiline_history_file] now we have persistent multiline_history
32
-
33
- == ripl-rc 0.2.1 -- 2011-04-11
34
-
35
- * [multiline] fixed history with editline (e.g. mac's build-in ruby)
36
-
37
- == ripl-rc 0.2.0 -- 2011-04-10
38
-
39
- * [ ripl-rc] tested with MRI 1.8.7, 1.9.2 and Rubinius 1.2.3, JRuby 1.6.0
40
- * [ ripl-rc] fixed some conflicts with bundler
41
- * [ ripl-rc] internal structure rearrangement
42
- * [ ripl-rc] all plugins now have runtime enable/disable ability
43
- e.g. run `Ripl.disable_color` to disable coloring,
44
- `Ripl.enable_color` to enable again.
45
- * [multiline] some tweak to make it more accurate
46
- * [last_exception] save last exception in Ripl.last_exception
47
-
48
- == ripl-rc 0.1.5 -- 2011-03-26
49
-
50
- * [ bin] shows a better error message when ripl-rails can't be found
51
- * [ ripl-rc] made require 'ripl-rc' works like require 'ripl/rc'
52
- * [multiline] fixed regexp warning on ruby 1.8.7
53
- * [multiline] fixed history when using multiline
54
-
55
- == ripl-rc 0.1.4 -- 2011-03-01
56
-
57
- * [ color] fix syntax error; sorry, i definitely need tests.. :s
58
-
59
- == ripl-rc 0.1.3 -- 2011-02-28
60
-
61
- * [ bin] added `ripl rc` and `ripl rc rails` commands
62
- * [noirbrc] added that don't read ~/.irbrc by default
63
- * [ anchor] use short_inspect
64
- * [ anchor] fixed a bug that cannot display nil
65
- * [ color] fixed a bug that displaying some values as Object. see [9a64495]
66
- * [ color] colorize error output as well
67
- * [squeeze_history] max 500 items
68
- * [strip_backtrace] fixed cwd, don't trace if it's a syntax error
69
-
70
- == ripl-rc 0.1.2 -- 2011-02-25
71
-
72
- * [ rc] rearranged require order
73
- * [ plugin] added anchor, like pry. usage: Ripl.anchor(binding) # or obj
74
- * [ plugin] added multiline, which works better with anchor
75
- * [ plugin] added mkdir_history, which tries to mkdir -p on history directory
76
- * [strip_backtrace] fix functionality for custom name (anchor)
77
-
78
- == ripl-rc 0.1.1 -- 2011-02-24
79
-
80
- * [ plugin] added strip_backtrace
81
- * [general] now use Ripl::Rc::U.include(YourExtension) to customize details
82
- * [ color] use Ripl.config[:rc_color] to configure color schema
83
-
84
- == ripl-rc 0.1.0 -- 2011-02-23
85
-
86
- * release early, release often
data/TODO DELETED
@@ -1,6 +0,0 @@
1
- = ripl-rc todo list
2
-
3
- * tests for each plugin
4
- * doc
5
-
6
- * read multiline histroy in irb_history
@@ -1,38 +0,0 @@
1
-
2
- require 'rib'
3
- require 'fileutils'
4
-
5
- module Rib::HistoryFile
6
- include Rib::Plugin
7
- Shell.use(self)
8
-
9
- def before_loop
10
- return super if HistoryFile.disabled?
11
- config[:history_file] ||= '~/.config/rib/history.rb'
12
- config[:history_size] ||= 500
13
- FileUtils.mkdir_p(File.dirname(history_file))
14
- super
15
- end
16
-
17
- def get_input
18
- return super if HistoryFile.disabled?
19
- (history << super).last
20
- end
21
-
22
- def read_history
23
- return super if HistoryFile.disabled?
24
- File.exist?(history_file) && history.empty? &&
25
- File.readlines(history_file).each{ |e| history << e.chomp }
26
- end
27
-
28
- def write_history
29
- return super if HistoryFile.disabled?
30
- File.open(history_file, 'w'){ |f|
31
- f.puts(history.to_a.last(config[:history_size]).join("\n")) }
32
- end
33
-
34
- private
35
- def history_file
36
- @history_file ||= File.expand_path(config[:history_file])
37
- end
38
- end
@@ -1,77 +0,0 @@
1
-
2
- require 'rib'
3
-
4
- # from https://github.com/janlelis/ripl-multi_line
5
- module Rib::Multiline
6
- include Rib::Plugin
7
- Shell.use(self)
8
-
9
- # test those:
10
- # ruby -e '"'
11
- # ruby -e '{'
12
- # ruby -e '['
13
- # ruby -e '('
14
- # ruby -e '/'
15
- # ruby -e 'class C'
16
- # ruby -e 'def f'
17
- # ruby -e 'begin'
18
- ERROR_REGEXP = Regexp.new(
19
- [ # string or regexp
20
- "unterminated \\w+ meets end of file",
21
- # mri and rubinius
22
- "syntax error, unexpected \\$end",
23
- # rubinius
24
- "expecting '.+'( or '.+')*",
25
- # jruby
26
- "syntax error, unexpected end-of-file",
27
- ].join('|'))
28
-
29
- def prompt
30
- return super if Multiline.disabled?
31
- if multiline_buffer.empty?
32
- super
33
- else
34
- "#{' '*(config[:prompt].size-2)}| "
35
- end
36
- end
37
-
38
- def loop_once
39
- return super if Multiline.disabled?
40
- catch(:multiline_cont) do
41
- super
42
- multiline_buffer.clear
43
- end
44
- end
45
-
46
- def loop_eval(input)
47
- return super if Multiline.disabled?
48
- multiline_buffer << input
49
- super(multiline_buffer.join("\n"))
50
- end
51
-
52
- def print_eval_error(e)
53
- return super if Multiline.disabled?
54
- if e.is_a?(SyntaxError) && e.message =~ ERROR_REGEXP
55
- throw :multiline_cont
56
- else
57
- super
58
- end
59
- end
60
-
61
- def handle_interrupt
62
- return super if Multiline.disabled?
63
- if multiline_buffer.empty?
64
- super
65
- else
66
- line = multiline_buffer.pop
67
- print "[removed this line: #{line}]"
68
- super
69
- throw :multiline_cont
70
- end
71
- end
72
-
73
- private
74
- def multiline_buffer
75
- @multiline_buffer ||= []
76
- end
77
- end
@@ -1,37 +0,0 @@
1
-
2
- require 'rib/core/history_file'
3
-
4
- module Rib::SqueezeHistory
5
- include Rib::Plugin
6
- Shell.use(self)
7
-
8
- # squeeze history on memory too
9
- def eval_input input
10
- return super if SqueezeHistory.disabled?
11
- history.pop if input.strip == '' ||
12
- (history.size > 1 && input == history.to_a[-2])
13
- # EditLine is really broken, to_a is needed for it
14
- super
15
- end
16
-
17
- # write squeezed history
18
- def write_history
19
- return super if SqueezeHistory.disabled?
20
- @history = P.squeeze_history(history)
21
- super
22
- end
23
-
24
- module Imp
25
- def squeeze_history history
26
- history.to_a.inject([]){ |result, item|
27
- if result.last == item || item.strip == ''
28
- result
29
- else
30
- result << item
31
- end
32
- }
33
- end
34
- end
35
-
36
- Plugin.extend(Imp)
37
- end