rib 0.0.1 → 0.1.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 (50) hide show
  1. data/.gitignore +6 -0
  2. data/.gitmodules +3 -0
  3. data/.travis.yml +9 -0
  4. data/2011-02-28.md +203 -0
  5. data/CHANGES +86 -0
  6. data/CONTRIBUTORS +2 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE +201 -0
  9. data/README +190 -0
  10. data/README.md +190 -0
  11. data/Rakefile +20 -0
  12. data/TODO +6 -0
  13. data/lib/rib.rb +42 -0
  14. data/lib/rib/all.rb +4 -0
  15. data/lib/rib/api.rb +105 -0
  16. data/lib/rib/core.rb +5 -0
  17. data/lib/rib/core/completion.rb +22 -0
  18. data/lib/rib/core/history_file.rb +38 -0
  19. data/lib/rib/core/readline.rb +19 -0
  20. data/lib/rib/core/underscore.rb +53 -0
  21. data/lib/rib/debug.rb +3 -0
  22. data/lib/rib/more.rb +12 -0
  23. data/lib/rib/more/color.rb +98 -0
  24. data/lib/rib/more/multiline.rb +77 -0
  25. data/lib/rib/more/multiline_history.rb +31 -0
  26. data/lib/rib/more/multiline_history_file.rb +37 -0
  27. data/lib/rib/more/squeeze_history.rb +37 -0
  28. data/lib/rib/more/strip_backtrace.rb +43 -0
  29. data/lib/rib/plugin.rb +56 -0
  30. data/lib/rib/runner.rb +106 -0
  31. data/lib/rib/shell.rb +43 -0
  32. data/lib/rib/test.rb +25 -0
  33. data/lib/rib/version.rb +4 -0
  34. data/lib/rib/zore.rb +3 -0
  35. data/lib/rib/zore/anchor.rb +69 -0
  36. data/lib/rib/zore/edit.rb +33 -0
  37. data/rib.gemspec +104 -0
  38. data/screenshot.png +0 -0
  39. data/task/.gitignore +1 -0
  40. data/task/gemgem.rb +182 -0
  41. data/test/core/test_completion.rb +18 -0
  42. data/test/core/test_history_file.rb +57 -0
  43. data/test/core/test_readline.rb +21 -0
  44. data/test/core/test_underscore.rb +41 -0
  45. data/test/more/test_color.rb +28 -0
  46. data/test/more/test_squeeze_history.rb +43 -0
  47. data/test/test_api.rb +20 -0
  48. data/test/test_plugin.rb +38 -0
  49. data/test/test_shell.rb +82 -0
  50. metadata +77 -13
data/README ADDED
@@ -0,0 +1,190 @@
1
+ # ripl-rc
2
+
3
+ by Lin Jen-Shin ([godfat](http://godfat.org))
4
+
5
+ ## LINKS:
6
+
7
+ * [github](https://github.com/godfat/ripl-rc)
8
+ * [rubygems](http://rubygems.org/gems/ripl-rc)
9
+
10
+ ## DESCRIPTION:
11
+
12
+ ripl plugins collection, take you want, leave you don't.
13
+
14
+ ## REQUIREMENTS:
15
+
16
+ * Tested with MRI 1.8.7, 1.9.2 and Rubinius 1.2.3, JRuby 1.6.0
17
+ * ripl
18
+
19
+ ## INSTALLATION:
20
+
21
+ gem install ripl-rc
22
+
23
+ ## SYNOPSIS:
24
+
25
+ If you don't know what is __ripl__, or just want to have an
26
+ overview of what does __ripl-rc__ do, then you can use it as
27
+ a command line tool:
28
+
29
+ ripl rc
30
+
31
+ This can be used to run rails console, too. First install
32
+ _ripl-rails_ by `gem install ripl-rails` then run this:
33
+
34
+ ripl rc rails
35
+
36
+ Then you'll have a _ripl-rc_ flavored rails console without
37
+ setting anything (i.e. `~/.riplrc`)
38
+
39
+ If you already know what is _ripl_, you might want to setup
40
+ yourself, to be better control what you might want and what
41
+ you might not want. Then checkout FEATURES for all plugins
42
+ you can put in `~/.riplrc`.
43
+
44
+ If you want to enable all plugins, the use this:
45
+
46
+ require 'ripl/rc'
47
+
48
+ Another thing which might worth to be mentioned is
49
+ `ripl/rc/anchor`, which is a _pry_ like feature built into
50
+ ripl. You can embed two things into ripl, one is any object:
51
+
52
+ Ripl.anchor your_object_want_to_be_viewed_as_self
53
+
54
+ Another one is local binding inside a method:
55
+
56
+ Ripl.anchor binding
57
+
58
+ Then you can look through local variables inside a method
59
+ with an interactive environment. Anchor could be nested, too.
60
+ You can anchor another object inside a _ripl_ session. The number
61
+ shown in prompt is the level of anchors, started from 1.
62
+
63
+ ![Screenshot](https://github.com/godfat/ripl-rc/raw/master/screenshot.png)
64
+
65
+ Please read this blog post for other detail since I haven't
66
+ had time to update this README... Sorry about that.
67
+
68
+ * [a new feature mainly for anchor in ripl-rc ](http://blogger.godfat.org/2011/06/new-feature-mainly-for-anchor-in-ripl.html)
69
+
70
+ ## FEATURES:
71
+
72
+ upon session ends:
73
+
74
+ * `require 'ripl/rc/squeeze_history'`
75
+
76
+ Which squeezes the same input in history, both in memory
77
+ and history file.
78
+
79
+ * `require 'ripl/rc/mkdir_history'`
80
+
81
+ Which calls `mkdir -p` on directory which contains history
82
+ file. For example, I put my irb_history in an directory
83
+ might not exist before use: `~/.config/irb/irb_history`
84
+
85
+ * `require 'ripl/rc/ctrld_newline'`
86
+
87
+ Ruby 1.9.2 has no this problem in irb, but 1.8 and ripl do.
88
+ When hitting ctrl+d to exit ripl, it would print a newline
89
+ instead of messing up with shell prompt.
90
+
91
+ upon exception occurs:
92
+
93
+ * `require 'ripl/rc/last_exception'`
94
+
95
+ We can't access $! for last exception because input evaluation
96
+ is not in the block which rescues the exception, neither can we
97
+ update $! because it's a read only pseudo global variable.
98
+
99
+ This plugin makes last rescued exception stored in `Ripl.last_exception`
100
+
101
+ upon formatting output:
102
+
103
+ * `require 'ripl/rc/strip_backtrace'`
104
+
105
+ ripl prints the full backtrace upon exceptions, even the
106
+ exceptions come from interactive environment, making it
107
+ very verbose. This ripl plugin strips those backtrace.
108
+
109
+ * `require 'ripl/rc/color'`
110
+
111
+ There's ripl-color_result that make use of <a href="https://github.com/michaeldv/awesome_print">awesome_print</a>,
112
+ <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
113
+ awesome and too verbose, and the problem of coderay and
114
+ wirb is that they are both parser based. In ripl, this should
115
+ be as simple as just print different colors upon different
116
+ objects, instead of inspecting it and parsing it.
117
+
118
+ ripl/rc/color just uses a hash with Class to color mapping
119
+ to pick up which color should be used upon a ruby object.
120
+
121
+ To customize the color schema, inspect `Ripl.config[:rc_color]`
122
+
123
+ upon input:
124
+
125
+ * `require 'ripl/rc/multiline'`
126
+
127
+ I need some modification on ripl-multi_line to make prompt
128
+ work better, but not sure if I can come up a good fix and
129
+ try to convince the author to accept those patches. So I
130
+ just bundle and maintain it on my own. If you're using
131
+ ripl-rc, you could use this plugin, otherwise, keep using
132
+ ripl-multi_line.
133
+
134
+ * `require 'ripl/rc/eat_whites'`
135
+
136
+ irb will just give you another prompt upon an empty input,
137
+ while ripl would show you that your input is nil. I don't like
138
+ this, because sometimes I'll keep hitting enter to separate
139
+ between inspects. This plugin would skip inspect if the input
140
+ is empty just like irb.
141
+
142
+ special tool:
143
+
144
+ * `require 'ripl/rc/anchor'`
145
+
146
+ So this is my attempt to emulate pry in ripl. Instead
147
+ trying to make pry support irb_history, colorizing, etc.,
148
+ I think implement pry like feature in ripl is a lot easier.
149
+ No need to be fancy, I just need the basic functionality.
150
+
151
+ To use it, use:
152
+ <pre><code>Ripl.anchor your_object_want_to_be_viewed_as_self</code></pre>
153
+ or
154
+ <pre><code>Ripl.anchor binding</code></pre>
155
+ in your code. Other than pry ripl support, you might be
156
+ 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.
157
+
158
+ about config:
159
+
160
+ * `require 'ripl/rc/noirbrc'`
161
+
162
+ By default ripl is reading `~/.irbrc`. I don't think this
163
+ is what people still using irb would want, because the
164
+ configuration is totally different. This suppress that,
165
+ make it only read `~/.riplrc`
166
+
167
+ for lazies:
168
+
169
+ * `require 'ripl/rc'`
170
+
171
+ This requires anything above for you, and is what `ripl rc`
172
+ and `ripl rc rails` shell commands did.
173
+
174
+ ## LICENSE:
175
+
176
+ Apache License 2.0
177
+
178
+ Copyright (c) 2010-2011, Lin Jen-Shin (godfat)
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ <http://www.apache.org/licenses/LICENSE-2.0>
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,190 @@
1
+ # ripl-rc
2
+
3
+ by Lin Jen-Shin ([godfat](http://godfat.org))
4
+
5
+ ## LINKS:
6
+
7
+ * [github](https://github.com/godfat/ripl-rc)
8
+ * [rubygems](http://rubygems.org/gems/ripl-rc)
9
+
10
+ ## DESCRIPTION:
11
+
12
+ ripl plugins collection, take you want, leave you don't.
13
+
14
+ ## REQUIREMENTS:
15
+
16
+ * Tested with MRI 1.8.7, 1.9.2 and Rubinius 1.2.3, JRuby 1.6.0
17
+ * ripl
18
+
19
+ ## INSTALLATION:
20
+
21
+ gem install ripl-rc
22
+
23
+ ## SYNOPSIS:
24
+
25
+ If you don't know what is __ripl__, or just want to have an
26
+ overview of what does __ripl-rc__ do, then you can use it as
27
+ a command line tool:
28
+
29
+ ripl rc
30
+
31
+ This can be used to run rails console, too. First install
32
+ _ripl-rails_ by `gem install ripl-rails` then run this:
33
+
34
+ ripl rc rails
35
+
36
+ Then you'll have a _ripl-rc_ flavored rails console without
37
+ setting anything (i.e. `~/.riplrc`)
38
+
39
+ If you already know what is _ripl_, you might want to setup
40
+ yourself, to be better control what you might want and what
41
+ you might not want. Then checkout FEATURES for all plugins
42
+ you can put in `~/.riplrc`.
43
+
44
+ If you want to enable all plugins, the use this:
45
+
46
+ require 'ripl/rc'
47
+
48
+ Another thing which might worth to be mentioned is
49
+ `ripl/rc/anchor`, which is a _pry_ like feature built into
50
+ ripl. You can embed two things into ripl, one is any object:
51
+
52
+ Ripl.anchor your_object_want_to_be_viewed_as_self
53
+
54
+ Another one is local binding inside a method:
55
+
56
+ Ripl.anchor binding
57
+
58
+ Then you can look through local variables inside a method
59
+ with an interactive environment. Anchor could be nested, too.
60
+ You can anchor another object inside a _ripl_ session. The number
61
+ shown in prompt is the level of anchors, started from 1.
62
+
63
+ ![Screenshot](https://github.com/godfat/ripl-rc/raw/master/screenshot.png)
64
+
65
+ Please read this blog post for other detail since I haven't
66
+ had time to update this README... Sorry about that.
67
+
68
+ * [a new feature mainly for anchor in ripl-rc ](http://blogger.godfat.org/2011/06/new-feature-mainly-for-anchor-in-ripl.html)
69
+
70
+ ## FEATURES:
71
+
72
+ upon session ends:
73
+
74
+ * `require 'ripl/rc/squeeze_history'`
75
+
76
+ Which squeezes the same input in history, both in memory
77
+ and history file.
78
+
79
+ * `require 'ripl/rc/mkdir_history'`
80
+
81
+ Which calls `mkdir -p` on directory which contains history
82
+ file. For example, I put my irb_history in an directory
83
+ might not exist before use: `~/.config/irb/irb_history`
84
+
85
+ * `require 'ripl/rc/ctrld_newline'`
86
+
87
+ Ruby 1.9.2 has no this problem in irb, but 1.8 and ripl do.
88
+ When hitting ctrl+d to exit ripl, it would print a newline
89
+ instead of messing up with shell prompt.
90
+
91
+ upon exception occurs:
92
+
93
+ * `require 'ripl/rc/last_exception'`
94
+
95
+ We can't access $! for last exception because input evaluation
96
+ is not in the block which rescues the exception, neither can we
97
+ update $! because it's a read only pseudo global variable.
98
+
99
+ This plugin makes last rescued exception stored in `Ripl.last_exception`
100
+
101
+ upon formatting output:
102
+
103
+ * `require 'ripl/rc/strip_backtrace'`
104
+
105
+ ripl prints the full backtrace upon exceptions, even the
106
+ exceptions come from interactive environment, making it
107
+ very verbose. This ripl plugin strips those backtrace.
108
+
109
+ * `require 'ripl/rc/color'`
110
+
111
+ There's ripl-color_result that make use of <a href="https://github.com/michaeldv/awesome_print">awesome_print</a>,
112
+ <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
113
+ awesome and too verbose, and the problem of coderay and
114
+ wirb is that they are both parser based. In ripl, this should
115
+ be as simple as just print different colors upon different
116
+ objects, instead of inspecting it and parsing it.
117
+
118
+ ripl/rc/color just uses a hash with Class to color mapping
119
+ to pick up which color should be used upon a ruby object.
120
+
121
+ To customize the color schema, inspect `Ripl.config[:rc_color]`
122
+
123
+ upon input:
124
+
125
+ * `require 'ripl/rc/multiline'`
126
+
127
+ I need some modification on ripl-multi_line to make prompt
128
+ work better, but not sure if I can come up a good fix and
129
+ try to convince the author to accept those patches. So I
130
+ just bundle and maintain it on my own. If you're using
131
+ ripl-rc, you could use this plugin, otherwise, keep using
132
+ ripl-multi_line.
133
+
134
+ * `require 'ripl/rc/eat_whites'`
135
+
136
+ irb will just give you another prompt upon an empty input,
137
+ while ripl would show you that your input is nil. I don't like
138
+ this, because sometimes I'll keep hitting enter to separate
139
+ between inspects. This plugin would skip inspect if the input
140
+ is empty just like irb.
141
+
142
+ special tool:
143
+
144
+ * `require 'ripl/rc/anchor'`
145
+
146
+ So this is my attempt to emulate pry in ripl. Instead
147
+ trying to make pry support irb_history, colorizing, etc.,
148
+ I think implement pry like feature in ripl is a lot easier.
149
+ No need to be fancy, I just need the basic functionality.
150
+
151
+ To use it, use:
152
+ <pre><code>Ripl.anchor your_object_want_to_be_viewed_as_self</code></pre>
153
+ or
154
+ <pre><code>Ripl.anchor binding</code></pre>
155
+ in your code. Other than pry ripl support, you might be
156
+ 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.
157
+
158
+ about config:
159
+
160
+ * `require 'ripl/rc/noirbrc'`
161
+
162
+ By default ripl is reading `~/.irbrc`. I don't think this
163
+ is what people still using irb would want, because the
164
+ configuration is totally different. This suppress that,
165
+ make it only read `~/.riplrc`
166
+
167
+ for lazies:
168
+
169
+ * `require 'ripl/rc'`
170
+
171
+ This requires anything above for you, and is what `ripl rc`
172
+ and `ripl rc rails` shell commands did.
173
+
174
+ ## LICENSE:
175
+
176
+ Apache License 2.0
177
+
178
+ Copyright (c) 2010-2011, Lin Jen-Shin (godfat)
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ <http://www.apache.org/licenses/LICENSE-2.0>
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,20 @@
1
+
2
+ require "#{dir = File.dirname(__FILE__)}/task/gemgem"
3
+ Gemgem.dir = dir
4
+
5
+ ($LOAD_PATH << File.expand_path("#{Gemgem.dir}/lib")).uniq!
6
+
7
+ desc 'Generate gemspec'
8
+ task 'gem:spec' do
9
+ Gemgem.spec = Gemgem.create do |s|
10
+ require 'rib/version'
11
+ s.name = 'rib'
12
+ s.version = Rib::VERSION
13
+ s.executables = [s.name]
14
+
15
+ %w[bond] .each{ |g| s.add_runtime_dependency(g) }
16
+ %w[bacon rr].each{ |g| s.add_development_dependency(g) }
17
+ end
18
+
19
+ Gemgem.write
20
+ end
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ = ripl-rc todo list
2
+
3
+ * tests for each plugin
4
+ * doc
5
+
6
+ * read multiline histroy in irb_history
@@ -0,0 +1,42 @@
1
+
2
+ require 'rib/shell'
3
+
4
+ module Rib
5
+ module_function
6
+ def config
7
+ @config ||= {:config => '~/.config/rib/config.rb'}
8
+ end
9
+
10
+ def shells
11
+ @shells ||= []
12
+ end
13
+
14
+ def vars
15
+ @vars ||= {}
16
+ end
17
+
18
+ def shell
19
+ shells.last || begin
20
+ require_rc
21
+ (shells << Shell.new(config)).last
22
+ end
23
+ end
24
+
25
+ def plugins
26
+ Shell.ancestors[1..-1].select{ |a| a < Plugin }
27
+ end
28
+
29
+ def disable_plugins plugs=plugins
30
+ plugs.each(&:disable)
31
+ end
32
+
33
+ def enable_plugins plugs=plugins
34
+ plugs.each(&:enable)
35
+ end
36
+
37
+ def require_rc
38
+ config[:config] &&
39
+ File.exist?(rc = File.expand_path(config[:config])) &&
40
+ require(rc)
41
+ end
42
+ end