akitaonrails-utility_belt 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -75,19 +75,27 @@ If you're wondering why the method name is so ridiculously long, there's a story
75
75
 
76
76
  http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html
77
77
 
78
- == Read from and write to OS X clipboard
78
+ == Read from and write to OS X or Windows clipboard
79
+
80
+ In order to use Clipboard on Windows you must install the 'win32-clipboard' gem.
79
81
 
80
82
  To read:
81
83
 
82
- MacClipboard.read
84
+ Clipboard.read
83
85
 
84
86
  To write:
85
87
 
86
- MacClipboard.write("something")
88
+ Clipboard.write("something")
89
+
90
+ == Post your code to Pastie with one command (OS X and Windows only)
87
91
 
88
- == Post your code to Pastie with one command (OS X only)
92
+ You must first equip the UtilityBelt with pastie in your .irbrc:
93
+
94
+ UtilityBelt.equip(:pastie)
95
+
96
+ This line will also automatically equip the Clipboard, which is required to use pastie.
89
97
 
90
- First copy some code into your clipboard, or put it there with the MacClipboard.write() class method. Then use the command:
98
+ First copy some code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command:
91
99
 
92
100
  pastie
93
101
 
@@ -95,7 +103,7 @@ or the shortcut version:
95
103
 
96
104
  pst
97
105
 
98
- Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X only because it uses the MacClipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)
106
+ Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X and Windows only because it uses the Clipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)
99
107
 
100
108
  == Unix-style history buffer
101
109
 
data/html/usage.html CHANGED
@@ -1,298 +1,304 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
- <meta name="description" content="Baddest Ruby gem evar." />
7
- <meta name="keywords" content="ruby, giles bowkett, batman, utility belt, gem, attack of the killer tomatoes" />
8
- <meta name="author" content="Giles Bowkett / Original design: Andreas Viklund - http://andreasviklund.com/" />
9
- <link rel="stylesheet" type="text/css" href="andreas00.css" media="screen,projection" />
10
- <title>Utility Belt: Usage</title>
11
- </head>
12
-
13
- <body>
14
- <div id="wrap">
15
- <div id="header">
16
- <h1><a href="http://utilitybelt.rubyforge.org">Utility Belt</a></h1>
17
- <p><strong>IRB tools, tricks, and techniques</strong></p>
18
- </div>
19
-
20
- <div id="avmenu">
21
- <h2 class="hide">Site menu:</h2>
22
- <ul>
23
- <li><a href="index.html">Overview</a></li>
24
- <li><a href="usage.html">Usage</a></li>
25
- <li><a href="authorship.html">Authorship</a></li>
26
- <li><a href="http://rubyforge.org/projects/utilitybelt/">RubyForge Project</a></li>
27
- </ul>
28
-
29
- </div>
30
-
31
- <div id="contentwide">
32
- <h2>Synopsis And Usage</h2>
33
-
34
-
35
- <h3>SYNOPSIS</h3>
36
-
37
- <p>Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.</p>
38
-
39
- <p>Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\<username>\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes.</p>
40
-
41
- <p>Adding Utility Belt to your .irbrc is easy:</p>
42
-
43
- <pre>require 'rubygems'
44
- require 'utility_belt'</pre>
45
-
46
- <p>To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more.</p>
47
-
48
- <h3>USAGE</h3>
49
-
50
- <p>Using each of Utility Belt's tools is different:</p>
51
-
52
- <h4>Interactively edit IRB code in your preferred text editor</h4>
53
-
54
- <p>If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command:</p>
55
-
56
- <pre>edit_interactively(:the_name_of_my_editor)</pre>
57
-
58
- <p>or</p>
59
-
60
- <pre>edit_interactively("the name of my editor")</pre>
61
-
62
- <p>or</p>
63
-
64
- <pre>edit_interactively("/the/path/to/my/editor")</pre>
65
-
66
- <p>If you're wondering why the method name is so ridiculously long, <a href="http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html" title="Giles Bowkett: Utility Belt vs. Rails">there's a story there</a>.</p>
67
-
68
- <h4>Read from and write to OS X clipboard</h4>
69
-
70
- <p>To read:</p>
71
-
72
- <pre>MacClipboard.read</pre>
73
-
74
- <p>To write:</p>
75
-
76
- <pre>MacClipboard.write("something")</pre>
77
-
78
- <h4>Post your code to Pastie with one command (OS X only)</h4>
79
-
80
- <p>First copy some code into your clipboard, or put it there with the MacClipboard.write() class method. Then use the command:</p>
81
-
82
- <pre>pastie</pre>
83
-
84
- <p>or the shortcut version:</p>
85
-
86
- <pre>pst</pre>
87
-
88
- <p>Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X only because it uses the MacClipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)</p>
89
-
90
- <h4>Unix-style history buffer</h4>
91
-
92
- <p>Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command.</p>
93
-
94
- <h4>Write command history to file or vi</h4>
95
-
96
- <p>To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi".</p>
97
-
98
- <h4>Grep classes and methods for strings</h4>
99
-
100
- <p>Classes:</p>
101
-
102
- <pre>&gt;&gt; grep_classes(&quot;ixnum&quot;)
103
- #=&gt; [&quot;Fixnum&quot;]
104
-
105
- &gt;&gt; grep_classes(&quot;num&quot;)
106
- #=&gt; [&quot;Bignum&quot;, &quot;Fixnum&quot;, &quot;Numeric&quot;, &quot;REXML::SyncEnumerator&quot;]</pre>
107
-
108
- <p>Methods:</p>
109
-
110
- <pre>&gt;&gt; &quot;any arbitrary string&quot;.grep_methods(&quot;pretty&quot;)
111
- #=&gt; [&quot;pretty_inspect&quot;, &quot;pretty_print_instance_variables&quot;,
112
- &quot;pretty_print_inspect&quot;, &quot;pretty_print&quot;, &quot;pretty_print_cycle&quot;]
113
-
114
- &gt;&gt; 32.grep_methods(&quot;*&quot;)
115
- #=&gt; [&quot;*&quot;, &quot;**&quot;]</pre>
116
-
117
- <p>At some point it'll probably be a good idea to add regex support for these methods. (Of course if I do that, I'll probably have to change the name from grep to ack.)</p>
118
-
119
- <h4>Verbosity controls for regular IRB and Rails console</h4>
120
-
121
- <p>regular IRB: "verbose" or "v" / "quiet" or "q"</p>
122
-
123
- <p>Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)</p>
124
-
125
- <h4>Finder shortcuts for Rails console</h4>
126
-
127
- <pre>user(:all) / user(1)</pre>
128
-
129
- <p>instead of</p>
130
-
131
- <pre>User.find(:all) / User.find(1)</pre>
132
-
133
- <p>Supports arbitrarily complex finds.</p>
134
-
135
- <h4>Upload shortcut for Amazon S3</h4>
136
-
137
- <p>First, define your secret keys in your environment variables:</p>
138
-
139
- <pre>export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
140
- export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'</pre>
141
-
142
- <p>(Obviously, replace those with actual values.)</p>
143
-
144
- <p>Then, you can use</p>
145
-
146
- <pre>aws_upload("bucket_name","filename")</pre>
147
-
148
- <p>To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see <a href="http://amazon.rubyforge.org" title="AWS::S3 - Ruby Library for Amazon Simple Storage Service (S3)">amazon.rubyforge.org</a> for details on that.</p>
149
-
150
- <p>A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:</p>
151
-
152
- <pre>def my_bucket_name(filename)
153
- aws_upload("my_default_bucket",filename)
154
- end</pre>
155
-
156
- <h4>Command-line Amazon S3 upload script</h4>
157
-
158
- <p>Utility Belt also includes <code>amazon</code>, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:</p>
159
-
160
- <pre>amazon -b my_bucket_name filename other_filename</pre>
161
-
162
- <p>(For any arbitrary number of filenames.)</p>
163
-
164
- <p>Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is</p>
165
-
166
- <pre>amazon -b blog_files some_file.name</pre>
167
-
168
- <p>Or</p>
169
-
170
- <pre>amazon --bucket blog_files some_file.name</pre>
171
-
172
- <p>And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash:</p>
173
-
174
- <pre>alias b1="amazon --bucket my_main_bucket $1"
175
- alias b2="amazon --bucket my_other_bucket $1"</pre>
176
-
177
- <p>And then you would only have to type:</p>
178
-
179
- <pre>b1 file.name</pre>
180
-
181
- <p>And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam.</p>
182
-
183
- <h4>Command-line Google shortcut (OS X only)</h4>
184
-
185
- <p>To pop open a new window in your default browser with Google search results for a given search term, do:</p>
186
-
187
- <pre>google "any given term"</pre>
188
-
189
- <p>For one-word terms, you can omit the quotes:</p>
190
-
191
- <pre>google term</pre>
192
-
193
- <p>If you already have the search term in your clipboard, you can just type:</p>
194
-
195
- <pre>google</pre>
196
-
197
- <p>(The last approach is useful for unusual command-line error messages.)</p>
198
-
199
- <h4>Auto-indentation</h4>
200
-
201
- <p>Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.)</p>
202
-
203
- <h4>_ special variable (like Unix shell var !!)</h4>
204
-
205
- <p>More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing.</p>
206
-
207
- <p>Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need.</p>
208
-
209
- <h4>Extremely basic themes for Wirble syntax coloring</h4>
210
-
211
- <p>Utility Belt incorporates <a href="http://pablotron.org/software/wirble/" title="Pablotron: Wirble">Wirble</a> as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc:</p>
212
-
213
- <pre>UtilityBelt::Themes.background(:light)</pre>
214
-
215
- <p>To revert back to the default, just use this:</p>
216
-
217
- <pre>UtilityBelt::Themes.background(:dark)</pre>
218
-
219
- <p>To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.</p>
220
-
221
- <h4>Pascal/JavaScript-style "with" statement</h4>
222
-
223
- <p>I use this with RSpec's spec_helper. Instead of:</p>
224
-
225
- <pre>Spec::Runner.configure do |config|
226
- config.use_transactional_fixtures = true
227
- config.use_instantiated_fixtures = false
228
- config.fixture_path = RAILS_ROOT + '/spec/fixtures'
229
- config.mock_with :flexmock
230
- end</pre>
231
-
232
- <p>I do this:</p>
233
-
234
- <pre>Spec::Runner.configure do |config|
235
- with(config) do
236
- use_transactional_fixtures = true
237
- use_instantiated_fixtures = false
238
- fixture_path = RAILS_ROOT + '/spec/fixtures'
239
- mock_with :flexmock
240
- end
241
- end</pre>
242
-
243
- <p>Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.</p>
244
-
245
- <h4>String#to_proc</h4>
246
-
247
- <p>Syntactic sugar for functional programming. (<a href="http://weblog.raganwald.com/2007/10/stringtoproc.html" title="String#to_proc">More detail here</a>.) Rails' Symbol#to_proc is also included.</p>
248
-
249
- <pre>(1..3).map(&amp;&apos;*2&apos;) =&gt; [2, 4, 6]
250
- (1..3).map(&amp;&apos;[-1, _, 0]&apos;) =&gt; [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
251
- (1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;[2]&apos;) =&gt; [2, 4, 6]
252
- (1..5).select(&amp;&apos;&gt;2&apos;) =&gt; [3, 4, 5]
253
- (1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;.call(2)&apos;) =&gt; [2, 4, 6]
254
- [5].map(&amp;&quot;(1.._).inject(&amp;&apos;*&apos;)&quot;) =&gt; [120]</pre>
255
-
256
- <h4>Add and subtract Hashes with + and -</h4>
257
-
258
- <pre>{:a =&gt; :b} + {:c =&gt; :d} = {:a =&gt; :b, :c =&gt; :d}
259
- {:a =&gt; :b, :c =&gt; :d} - {:c =&gt; :d} = {:a =&gt; :b}
260
- {:a =&gt; :b, :c =&gt; :d} - :c = {:a =&gt; :b}</pre>
261
-
262
- <p>You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.)</p>
263
-
264
-
265
- <h4>Grammatically-correct is_an? method - no more "is_a? Array" statements</h4>
266
-
267
- <pre>&gt;&gt; [].is_an? Array
268
- #=&gt; true</pre>
269
-
270
- <p>Most people don't care, but personally, "is_a? Array" drives me completely insane.</p>
271
-
272
- <h4>Object#not</h4>
273
-
274
- <p>Replace this:</p>
275
-
276
- <pre>if !response.incomplete? &amp;&amp; !response.invalid? &amp;&amp; response.total &gt; 0</pre>
277
-
278
- <p>With this:</p>
279
-
280
- <pre>if response.not.incomplete? &amp;&amp; response.not.invalid? &amp;&amp; response.total &gt; 0</pre>
281
-
282
- <p>Syntactic sugar for boolean conditions. (<a href="http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html" title="Jay Fields Thoughts: Ruby: Adding a "not" method for readability">More detail here</a>.)</p>
283
-
284
- <h4>One-character exit command</h4>
285
-
286
- <pre>x</pre>
287
-
288
- <p>Because life is too short to type whole words.</p>
289
-
290
-
291
- </div>
292
-
293
- <div id="footer">
294
- <p>Copyright &copy; 2007 Giles Bowkett | Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.</p>
295
- </div>
296
- </div>
297
- </body>
298
- </html>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+ <meta name="description" content="Baddest Ruby gem evar." />
7
+ <meta name="keywords" content="ruby, giles bowkett, batman, utility belt, gem, attack of the killer tomatoes" />
8
+ <meta name="author" content="Giles Bowkett / Original design: Andreas Viklund - http://andreasviklund.com/" />
9
+ <link rel="stylesheet" type="text/css" href="andreas00.css" media="screen,projection" />
10
+ <title>Utility Belt: Usage</title>
11
+ </head>
12
+
13
+ <body>
14
+ <div id="wrap">
15
+ <div id="header">
16
+ <h1><a href="http://utilitybelt.rubyforge.org">Utility Belt</a></h1>
17
+ <p><strong>IRB tools, tricks, and techniques</strong></p>
18
+ </div>
19
+
20
+ <div id="avmenu">
21
+ <h2 class="hide">Site menu:</h2>
22
+ <ul>
23
+ <li><a href="index.html">Overview</a></li>
24
+ <li><a href="usage.html">Usage</a></li>
25
+ <li><a href="authorship.html">Authorship</a></li>
26
+ <li><a href="http://rubyforge.org/projects/utilitybelt/">RubyForge Project</a></li>
27
+ </ul>
28
+
29
+ </div>
30
+
31
+ <div id="contentwide">
32
+ <h2>Synopsis And Usage</h2>
33
+
34
+
35
+ <h3>SYNOPSIS</h3>
36
+
37
+ <p>Utility Belt gives you a ton of new options and techniques in IRB. (You may find yourself putting its language patches in actual projects as well.) The way to use Utility Belt is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.</p>
38
+
39
+ <p>Windows users have a couple options. The easiest is to define an environment variable called IRBRC and set it to the full path of your irbrc (e.g. "C:\Documents and Settings\<username>\_irbrc"). Presto, .irbrc for Windows. You could also set your HOME-Variable to any directory you want and put your ".irbrc" in there. (It needs to be called ".irbrc", "_irbrc" won't work). Since Windows Explorer won't let you create a file with a dot in the beginning, use any text editor (Notepad will do just fine) and "Save As" to save it as ".irbrc". (The quotation marks make the magic happen.) We don't recommend this if you're also using MSYS or Cygwin, as they use the same variable for their own purposes.</p>
40
+
41
+ <p>Adding Utility Belt to your .irbrc is easy:</p>
42
+
43
+ <pre>require 'rubygems'
44
+ require 'utility_belt'</pre>
45
+
46
+ <p>To use the Amazon shortcuts, you also need to set some environment variables. See the section on S3 under "Usage" for more. Also, if your terminal has a light background, you'll need to enable the light-background syntax coloring theme - see the section on themes under "Usage" for more.</p>
47
+
48
+ <h3>USAGE</h3>
49
+
50
+ <p>Using each of Utility Belt's tools is different:</p>
51
+
52
+ <h4>Interactively edit IRB code in your preferred text editor</h4>
53
+
54
+ <p>If your preferred text editor is vi(m), emacs, or TextMate, there are built-in commands: vi, emacs, and mate, respectively. To use another editor, use this command:</p>
55
+
56
+ <pre>edit_interactively(:the_name_of_my_editor)</pre>
57
+
58
+ <p>or</p>
59
+
60
+ <pre>edit_interactively("the name of my editor")</pre>
61
+
62
+ <p>or</p>
63
+
64
+ <pre>edit_interactively("/the/path/to/my/editor")</pre>
65
+
66
+ <p>If you're wondering why the method name is so ridiculously long, <a href="http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html" title="Giles Bowkett: Utility Belt vs. Rails">there's a story there</a>.</p>
67
+
68
+ <h4>Read from and write to OS X or Windows clipboard</h4>
69
+
70
+ <p>To read:</p>
71
+
72
+ <pre>Clipboard.read</pre>
73
+
74
+ <p>To write:</p>
75
+
76
+ <pre>Clipboard.write("something")</pre>
77
+
78
+ <h4>Post your code to Pastie with one command (OS X and Windows only)</h4>
79
+
80
+ <p>You must first equip the UtilityBelt with pastie in your .irbrc:</p>
81
+
82
+ <pre>UtilityBelt.equip(:pastie)</pre>
83
+
84
+ <p>This line will also automatically equip the Clipboard, which is required to use pastie.</p>
85
+
86
+ <p>First copy some code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command:</p>
87
+
88
+ <pre>pastie</pre>
89
+
90
+ <p>or the shortcut version:</p>
91
+
92
+ <pre>pst</pre>
93
+
94
+ <p>Note that this method currently auto-formats all code as Ruby. Support for other languages is possible but not implemented yet. Also, this code is OS X and Windows only because it uses the Clipboard. (A platform-agnostic version without the clipboard aspect is certainly possible.)</p>
95
+
96
+ <h4>Unix-style history buffer</h4>
97
+
98
+ <p>Use "h" or "history" to view your command history, and "h! 123" to re-invoke command #123 in your buffer. "h!" with no args will run the last command.</p>
99
+
100
+ <h4>Write command history to file or vi</h4>
101
+
102
+ <p>To write your history to a file, use "history_write('/path/to/file')". To edit your history in vi, use "history_to_vi" or its shortcut alias "hvi".</p>
103
+
104
+ <h4>Grep classes and methods for strings</h4>
105
+
106
+ <p>Classes:</p>
107
+
108
+ <pre>&gt;&gt; grep_classes(&quot;ixnum&quot;)
109
+ #=&gt; [&quot;Fixnum&quot;]
110
+
111
+ &gt;&gt; grep_classes(&quot;num&quot;)
112
+ #=&gt; [&quot;Bignum&quot;, &quot;Fixnum&quot;, &quot;Numeric&quot;, &quot;REXML::SyncEnumerator&quot;]</pre>
113
+
114
+ <p>Methods:</p>
115
+
116
+ <pre>&gt;&gt; &quot;any arbitrary string&quot;.grep_methods(&quot;pretty&quot;)
117
+ #=&gt; [&quot;pretty_inspect&quot;, &quot;pretty_print_instance_variables&quot;,
118
+ &quot;pretty_print_inspect&quot;, &quot;pretty_print&quot;, &quot;pretty_print_cycle&quot;]
119
+
120
+ &gt;&gt; 32.grep_methods(&quot;*&quot;)
121
+ #=&gt; [&quot;*&quot;, &quot;**&quot;]</pre>
122
+
123
+ <p>At some point it'll probably be a good idea to add regex support for these methods. (Of course if I do that, I'll probably have to change the name from grep to ack.)</p>
124
+
125
+ <h4>Verbosity controls for regular IRB and Rails console</h4>
126
+
127
+ <p>regular IRB: "verbose" or "v" / "quiet" or "q"</p>
128
+
129
+ <p>Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)</p>
130
+
131
+ <h4>Finder shortcuts for Rails console</h4>
132
+
133
+ <pre>user(:all) / user(1)</pre>
134
+
135
+ <p>instead of</p>
136
+
137
+ <pre>User.find(:all) / User.find(1)</pre>
138
+
139
+ <p>Supports arbitrarily complex finds.</p>
140
+
141
+ <h4>Upload shortcut for Amazon S3</h4>
142
+
143
+ <p>First, define your secret keys in your environment variables:</p>
144
+
145
+ <pre>export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
146
+ export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'</pre>
147
+
148
+ <p>(Obviously, replace those with actual values.)</p>
149
+
150
+ <p>Then, you can use</p>
151
+
152
+ <pre>aws_upload("bucket_name","filename")</pre>
153
+
154
+ <p>To easily upload public-access files. This method will automatically connect to Amazon S3 for you, if your keys are defined in your environment variables. It also writes the resulting Amazon URL to your clipboard, if you're on OS X, so you can easily share the file with others. Note that you have to create the initial buckets manually - see <a href="http://amazon.rubyforge.org" title="AWS::S3 - Ruby Library for Amazon Simple Storage Service (S3)">amazon.rubyforge.org</a> for details on that.</p>
155
+
156
+ <p>A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:</p>
157
+
158
+ <pre>def my_bucket_name(filename)
159
+ aws_upload("my_default_bucket",filename)
160
+ end</pre>
161
+
162
+ <h4>Command-line Amazon S3 upload script</h4>
163
+
164
+ <p>Utility Belt also includes <code>amazon</code>, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:</p>
165
+
166
+ <pre>amazon -b my_bucket_name filename other_filename</pre>
167
+
168
+ <p>(For any arbitrary number of filenames.)</p>
169
+
170
+ <p>Anytime you want to upload a file to your default bucket on S3, for example, the "images" bucket for your blog - or the "mp3" bucket if you're running a blog like Projectionist - all you have to do is</p>
171
+
172
+ <pre>amazon -b blog_files some_file.name</pre>
173
+
174
+ <p>Or</p>
175
+
176
+ <pre>amazon --bucket blog_files some_file.name</pre>
177
+
178
+ <p>And you're good to go. Of course, if that were too many characters to type, you could always take it one step further with a shell script. For instance, in bash:</p>
179
+
180
+ <pre>alias b1="amazon --bucket my_main_bucket $1"
181
+ alias b2="amazon --bucket my_other_bucket $1"</pre>
182
+
183
+ <p>And then you would only have to type:</p>
184
+
185
+ <pre>b1 file.name</pre>
186
+
187
+ <p>And of course tab completion will handle all the typing of the file name, assuming you choose your file names deliberately ahead of time to make tab completion effective, in which case all you have to type is "b1 f[tab]" and bam.</p>
188
+
189
+ <h4>Command-line Google shortcut (OS X only)</h4>
190
+
191
+ <p>To pop open a new window in your default browser with Google search results for a given search term, do:</p>
192
+
193
+ <pre>google "any given term"</pre>
194
+
195
+ <p>For one-word terms, you can omit the quotes:</p>
196
+
197
+ <pre>google term</pre>
198
+
199
+ <p>If you already have the search term in your clipboard, you can just type:</p>
200
+
201
+ <pre>google</pre>
202
+
203
+ <p>(The last approach is useful for unusual command-line error messages.)</p>
204
+
205
+ <h4>Auto-indentation</h4>
206
+
207
+ <p>Just type as normally. This just enables built-in but underused functionality in IRB. (The IRB default auto-indentation isn't perfect, but it clobbers the living hell out of no indentation at all.)</p>
208
+
209
+ <h4>_ special variable (like Unix shell var !!)</h4>
210
+
211
+ <p>More activation of built-in but underused functionality in IRB. _ functions like !! in Unix, with one subtle difference. Instead of re-issuing the previous command in your history, it gives you the last result of evaluating a command. This means when you start a new IRB session, _ won't go to your history, it'll just give you nil, and it means that some commands can't be repeated exactly. Nine out of ten times, however, it's pretty much the same thing.</p>
212
+
213
+ <p>Note that when combined with the h! in the command history code, you basically have two synonyms for !! here. Neither one is an exact replica, but between the two of them, you should have what you need.</p>
214
+
215
+ <h4>Extremely basic themes for Wirble syntax coloring</h4>
216
+
217
+ <p>Utility Belt incorporates <a href="http://pablotron.org/software/wirble/" title="Pablotron: Wirble">Wirble</a> as a dependency. Wirble provides syntax coloring. Utility Belt allows you to choose between two syntax coloring themes: Wirble's default, and an alternate color set for terminals with light backgrounds. The default theme is enabled by default (duh), but if you have a terminal with a light background, you can enable the light-background theme just by putting the following line of code in your .irbrc:</p>
218
+
219
+ <pre>UtilityBelt::Themes.background(:light)</pre>
220
+
221
+ <p>To revert back to the default, just use this:</p>
222
+
223
+ <pre>UtilityBelt::Themes.background(:dark)</pre>
224
+
225
+ <p>To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.</p>
226
+
227
+ <h4>Pascal/JavaScript-style "with" statement</h4>
228
+
229
+ <p>I use this with RSpec's spec_helper. Instead of:</p>
230
+
231
+ <pre>Spec::Runner.configure do |config|
232
+ config.use_transactional_fixtures = true
233
+ config.use_instantiated_fixtures = false
234
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures'
235
+ config.mock_with :flexmock
236
+ end</pre>
237
+
238
+ <p>I do this:</p>
239
+
240
+ <pre>Spec::Runner.configure do |config|
241
+ with(config) do
242
+ use_transactional_fixtures = true
243
+ use_instantiated_fixtures = false
244
+ fixture_path = RAILS_ROOT + '/spec/fixtures'
245
+ mock_with :flexmock
246
+ end
247
+ end</pre>
248
+
249
+ <p>Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.</p>
250
+
251
+ <h4>String#to_proc</h4>
252
+
253
+ <p>Syntactic sugar for functional programming. (<a href="http://weblog.raganwald.com/2007/10/stringtoproc.html" title="String#to_proc">More detail here</a>.) Rails' Symbol#to_proc is also included.</p>
254
+
255
+ <pre>(1..3).map(&amp;&apos;*2&apos;) =&gt; [2, 4, 6]
256
+ (1..3).map(&amp;&apos;[-1, _, 0]&apos;) =&gt; [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
257
+ (1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;[2]&apos;) =&gt; [2, 4, 6]
258
+ (1..5).select(&amp;&apos;&gt;2&apos;) =&gt; [3, 4, 5]
259
+ (1..3).map(&amp;&apos;x -&gt; y -&gt; x * y&apos;).map(&amp;&apos;.call(2)&apos;) =&gt; [2, 4, 6]
260
+ [5].map(&amp;&quot;(1.._).inject(&amp;&apos;*&apos;)&quot;) =&gt; [120]</pre>
261
+
262
+ <h4>Add and subtract Hashes with + and -</h4>
263
+
264
+ <pre>{:a =&gt; :b} + {:c =&gt; :d} = {:a =&gt; :b, :c =&gt; :d}
265
+ {:a =&gt; :b, :c =&gt; :d} - {:c =&gt; :d} = {:a =&gt; :b}
266
+ {:a =&gt; :b, :c =&gt; :d} - :c = {:a =&gt; :b}</pre>
267
+
268
+ <p>You could already do this with Arrays; now you can do it with Hashes as well. (I was kinda surprised the first time I tried to do this and realized I'd have to write it myself.)</p>
269
+
270
+
271
+ <h4>Grammatically-correct is_an? method - no more "is_a? Array" statements</h4>
272
+
273
+ <pre>&gt;&gt; [].is_an? Array
274
+ #=&gt; true</pre>
275
+
276
+ <p>Most people don't care, but personally, "is_a? Array" drives me completely insane.</p>
277
+
278
+ <h4>Object#not</h4>
279
+
280
+ <p>Replace this:</p>
281
+
282
+ <pre>if !response.incomplete? &amp;&amp; !response.invalid? &amp;&amp; response.total &gt; 0</pre>
283
+
284
+ <p>With this:</p>
285
+
286
+ <pre>if response.not.incomplete? &amp;&amp; response.not.invalid? &amp;&amp; response.total &gt; 0</pre>
287
+
288
+ <p>Syntactic sugar for boolean conditions. (<a href="http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html" title="Jay Fields Thoughts: Ruby: Adding a "not" method for readability">More detail here</a>.)</p>
289
+
290
+ <h4>One-character exit command</h4>
291
+
292
+ <pre>x</pre>
293
+
294
+ <p>Because life is too short to type whole words.</p>
295
+
296
+
297
+ </div>
298
+
299
+ <div id="footer">
300
+ <p>Copyright &copy; 2007 Giles Bowkett | Design by <a href="http://andreasviklund.com">Andreas Viklund</a>.</p>
301
+ </div>
302
+ </div>
303
+ </body>
304
+ </html>
data/lib/utility_belt.rb CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  UTILITY_BELT_IRB_STARTUP_PROCS = {} unless Object.const_defined? :UTILITY_BELT_IRB_STARTUP_PROCS
7
7
 
8
- %w{rubygems utility_belt/equipper}.each {|internal_library| require internal_library}
8
+ %w{rubygems active_support utility_belt/equipper}.each {|internal_library| require internal_library}
9
9
 
10
10
  if Object.const_defined? :IRB
11
11
 
data/utility_belt.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  #require 'rubygems'
2
2
  SPEC = Gem::Specification.new do |s|
3
- s.name = "utility_belt"
4
- s.version = "1.0.12"
3
+ s.name = "akitaonrails-utility_belt"
4
+ s.version = "1.0.13"
5
5
  s.author = "Giles Bowkett"
6
6
  s.email = "gilesb@gmail.com"
7
7
  s.homepage = "http://utilitybelt.rubyforge.org"
8
- s.rubyforge_project = "utility_belt"
8
+ s.rubyforge_project = "akitaonrails-utility_belt"
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = "A grab-bag of IRB power user madness. -- now with linux"
11
11
  s.files = ["bin", "bin/amazon", "bin/google", "bin/pastie", "History.txt", "html", "html/andreas00.css", "html/authorship.html", "html/bg.gif", "html/front.jpg", "html/index.html", "html/menubg.gif", "html/menubg2.gif", "html/test.jpg", "html/usage.html", "lib", "lib/utility_belt", "lib/utility_belt/amazon_upload_shortcut.rb", "lib/utility_belt/clipboard.rb", "lib/utility_belt/command_history.rb", "lib/utility_belt/convertable_to_file.rb", "lib/utility_belt/equipper.rb", "lib/utility_belt/google.rb", "lib/utility_belt/hash_math.rb", "lib/utility_belt/interactive_editor.rb", "lib/utility_belt/irb_options.rb", "lib/utility_belt/irb_verbosity_control.rb", "lib/utility_belt/is_an.rb", "lib/utility_belt/language_greps.rb", "lib/utility_belt/not.rb", "lib/utility_belt/pastie.rb", "lib/utility_belt/pipe.rb", "lib/utility_belt/print_methods.rb", "lib/utility_belt/rails_finder_shortcut.rb", "lib/utility_belt/rails_verbosity_control.rb", "lib/utility_belt/string_to_proc.rb", "lib/utility_belt/symbol_to_proc.rb", "lib/utility_belt/webbrowser.rb", "lib/utility_belt/wirble.rb", "lib/utility_belt/with.rb", "lib/utility_belt.rb", "Manifest.txt", "README", "spec", "spec/convertable_to_file_spec.rb", "spec/equipper_spec.rb", "spec/hash_math_spec.rb", "spec/interactive_editor_spec.rb", "spec/language_greps_spec.rb", "spec/pastie_spec.rb", "spec/pipe_spec.rb", "spec/spec_helper.rb", "spec/string_to_proc_spec.rb", "spec/utility_belt_spec.rb", "utility_belt.gemspec"]
@@ -15,7 +15,8 @@ SPEC = Gem::Specification.new do |s|
15
15
  s.require_path = "lib"
16
16
  s.test_file = "spec/utility_belt_spec.rb"
17
17
  s.has_rdoc = true
18
- s.extra_rdoc_files = ["README"]
18
+ s.extra_rdoc_files = ["README"]
19
+ s.add_dependency("activesupport")
19
20
  s.add_dependency("wirble", ">= 0.1.2")
20
21
  s.add_dependency("aws-s3", ">= 0.5.1")
21
22
  s.add_dependency("Platform", ">= 0.4.0")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akitaonrails-utility_belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giles Bowkett
@@ -9,11 +9,22 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-13 00:00:00 -07:00
12
+ date: 2010-01-01 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: wirble
27
+ type: :runtime
17
28
  version_requirement:
18
29
  version_requirements: !ruby/object:Gem::Requirement
19
30
  requirements:
@@ -23,6 +34,7 @@ dependencies:
23
34
  version:
24
35
  - !ruby/object:Gem::Dependency
25
36
  name: aws-s3
37
+ type: :runtime
26
38
  version_requirement:
27
39
  version_requirements: !ruby/object:Gem::Requirement
28
40
  requirements:
@@ -32,6 +44,7 @@ dependencies:
32
44
  version:
33
45
  - !ruby/object:Gem::Dependency
34
46
  name: Platform
47
+ type: :runtime
35
48
  version_requirement:
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
@@ -41,6 +54,7 @@ dependencies:
41
54
  version:
42
55
  - !ruby/object:Gem::Dependency
43
56
  name: ruby2ruby
57
+ type: :runtime
44
58
  version_requirement:
45
59
  version_requirements: !ruby/object:Gem::Requirement
46
60
  requirements:
@@ -59,12 +73,10 @@ extensions: []
59
73
  extra_rdoc_files:
60
74
  - README
61
75
  files:
62
- - bin
63
76
  - bin/amazon
64
77
  - bin/google
65
78
  - bin/pastie
66
79
  - History.txt
67
- - html
68
80
  - html/andreas00.css
69
81
  - html/authorship.html
70
82
  - html/bg.gif
@@ -74,8 +86,6 @@ files:
74
86
  - html/menubg2.gif
75
87
  - html/test.jpg
76
88
  - html/usage.html
77
- - lib
78
- - lib/utility_belt
79
89
  - lib/utility_belt/amazon_upload_shortcut.rb
80
90
  - lib/utility_belt/clipboard.rb
81
91
  - lib/utility_belt/command_history.rb
@@ -102,7 +112,6 @@ files:
102
112
  - lib/utility_belt.rb
103
113
  - Manifest.txt
104
114
  - README
105
- - spec
106
115
  - spec/convertable_to_file_spec.rb
107
116
  - spec/equipper_spec.rb
108
117
  - spec/hash_math_spec.rb
@@ -116,6 +125,8 @@ files:
116
125
  - utility_belt.gemspec
117
126
  has_rdoc: true
118
127
  homepage: http://utilitybelt.rubyforge.org
128
+ licenses: []
129
+
119
130
  post_install_message:
120
131
  rdoc_options: []
121
132
 
@@ -135,10 +146,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
146
  version:
136
147
  requirements: []
137
148
 
138
- rubyforge_project: utility_belt
139
- rubygems_version: 1.2.0
149
+ rubyforge_project: akitaonrails-utility_belt
150
+ rubygems_version: 1.3.5
140
151
  signing_key:
141
- specification_version: 2
152
+ specification_version: 3
142
153
  summary: A grab-bag of IRB power user madness. -- now with linux
143
154
  test_files:
144
155
  - spec/utility_belt_spec.rb