flyrb 1.0.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History.txt +5 -0
  2. data/Manifest.txt +7 -0
  3. data/README +362 -0
  4. data/bin/amazon +16 -0
  5. data/bin/google +7 -0
  6. data/bin/pastie +7 -0
  7. data/flyrb.gemspec +22 -0
  8. data/html/andreas00.css +449 -0
  9. data/html/authorship.html +86 -0
  10. data/html/bg.gif +0 -0
  11. data/html/front.jpg +0 -0
  12. data/html/index.html +81 -0
  13. data/html/menubg.gif +0 -0
  14. data/html/menubg2.gif +0 -0
  15. data/html/test.jpg +0 -0
  16. data/html/usage.html +304 -0
  17. data/lib/flyrb/amazon_upload_shortcut.rb +25 -0
  18. data/lib/flyrb/clipboard.rb +52 -0
  19. data/lib/flyrb/command_history.rb +110 -0
  20. data/lib/flyrb/convertable_to_file.rb +34 -0
  21. data/lib/flyrb/equipper.rb +71 -0
  22. data/lib/flyrb/google.rb +33 -0
  23. data/lib/flyrb/hash_math.rb +13 -0
  24. data/lib/flyrb/interactive_editor.rb +78 -0
  25. data/lib/flyrb/irb_options.rb +3 -0
  26. data/lib/flyrb/irb_verbosity_control.rb +30 -0
  27. data/lib/flyrb/is_an.rb +4 -0
  28. data/lib/flyrb/language_greps.rb +28 -0
  29. data/lib/flyrb/not.rb +15 -0
  30. data/lib/flyrb/pastie.rb +34 -0
  31. data/lib/flyrb/pipe.rb +24 -0
  32. data/lib/flyrb/rails_finder_shortcut.rb +18 -0
  33. data/lib/flyrb/rails_verbosity_control.rb +8 -0
  34. data/lib/flyrb/string_to_proc.rb +72 -0
  35. data/lib/flyrb/symbol_to_proc.rb +30 -0
  36. data/lib/flyrb/wirble.rb +83 -0
  37. data/lib/flyrb/with.rb +21 -0
  38. data/lib/flyrb.rb +22 -0
  39. data/spec/convertable_to_file_spec.rb +31 -0
  40. data/spec/equipper_spec.rb +70 -0
  41. data/spec/flyrb_spec.rb +4 -0
  42. data/spec/hash_math_spec.rb +17 -0
  43. data/spec/interactive_editor_spec.rb +146 -0
  44. data/spec/language_greps_spec.rb +9 -0
  45. data/spec/pastie_spec.rb +92 -0
  46. data/spec/pipe_spec.rb +30 -0
  47. data/spec/spec_helper.rb +8 -0
  48. data/spec/string_to_proc_spec.rb +41 -0
  49. metadata +143 -0
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 1.0.0 / 2007-11-03
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
5
+
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/flyrb
6
+ lib/flyrb.rb
7
+ test/test_flyrb.rb
data/README ADDED
@@ -0,0 +1,362 @@
1
+ == Flyrb
2
+
3
+ previously utility_belt by Giles Bowkett (and many others): http://utilitybelt.rubyforge.org
4
+
5
+ == Why Hijack The Project?
6
+
7
+ Giles isn't maintaining it anymore and it didn't work with Ruby 1.9. Since I depend on the library quite a bit, I've decided to maintain a fork myself and others.
8
+
9
+ == Why Rename It?
10
+
11
+ Well Giles owns the namespace on Gemcutter and various other folks are maintaining their own forks. I think it'll be less confusing to simply leave utility_belt in 1.8 land and move forward with Flyrb in 1.9.
12
+
13
+ == DESCRIPTION
14
+
15
+ Flyrb is a grab-bag of tricks, tools, techniques, trifles, and toys for IRB, including convenience methods, language patches, and useful extensions. It also includes a couple command-line widgets. Its primary inspirations were an awesome gem called Wirble and a blog post by Amy Hoy called "Secrets Of The Rails Console Ninjas".
16
+
17
+ (http://slash7.com/articles/2006/12/21/secrets-of-the-rails-console-ninjas)
18
+
19
+ == INSTALL
20
+
21
+ sudo gem install flyrb
22
+
23
+ == FEATURES
24
+
25
+ * Interactively edit IRB code in your preferred text editor
26
+ * Read from and write to OS X clipboard
27
+ * Post your code to Pastie with one command (OS X only)
28
+ * Kick-ass Unix-style history buffer
29
+ * Write command history to file or vi
30
+ * Grep classes and methods for strings
31
+ * Verbosity controls for regular IRB and Rails console
32
+ * Finder shortcuts for Rails console
33
+ * Upload shortcut for Amazon S3
34
+ * Command-line Amazon S3 upload script
35
+ * Command-line Google shortcut (OS X only)
36
+ * Auto-indentation
37
+ * _ special variable (like Unix shell var !!)
38
+ * Extremely basic themes for Wirble syntax coloring
39
+ * Pascal/JavaScript-style "with" statement
40
+ * String#to_proc
41
+ * Add and subtract Hashes with + and -
42
+ * Grammatically-correct is_an? method - no more "is_a? Array" statements
43
+ * One-character exit command
44
+
45
+ == COMMUNITY EFFORT
46
+
47
+ The majority of this code was written by other people and compiled, nicked, nabbed, herded, gathered, copied, or pilfered by me (Giles Bowkett). See copyright notice for the credits. A lot of this code comes from blogs. Check out the source code for numerous links to the original posts the code came from. Thanks also to Bob Hutchison, Avdi Grimm, Marcus Derencius, Markus Prinz, Ben Bleything, Reginald Braithwaite-Lee, and Robert Berger for bug fixes, new features, documentation, and bug reports.
48
+
49
+ == SYNOPSIS
50
+
51
+ Flyrb 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 Flyrb is to edit, or create, your .irbrc file. This is analogous to a Unix .bashrc, .tcshrc, .profile, or similar file.
52
+
53
+ 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.
54
+
55
+ Adding Flyrb to your .irbrc is easy:
56
+
57
+ require 'rubygems'
58
+ require 'flyrb'
59
+
60
+ 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.
61
+
62
+ == USAGE
63
+
64
+ Using each of Flyrb's tools is different:
65
+
66
+ == Interactively edit IRB code in your preferred text editor
67
+
68
+ 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:
69
+
70
+ edit_interactively(:the_name_of_my_editor)
71
+
72
+ or
73
+
74
+ edit_interactively("the name of my editor")
75
+
76
+ or
77
+
78
+ edit_interactively("/the/path/to/my/editor")
79
+
80
+ If you're wondering why the method name is so ridiculously long, there's a story there:
81
+
82
+ http://gilesbowkett.blogspot.com/2007/12/flyrb-vs-rails.html
83
+
84
+ == Read from and write to OS X or Windows clipboard
85
+
86
+ In order to use Clipboard on Windows you must install the 'win32-clipboard' gem.
87
+
88
+ To read:
89
+
90
+ Clipboard.read
91
+
92
+ To write:
93
+
94
+ Clipboard.write("something")
95
+
96
+ == Post your code to Pastie with one command (OS X and Windows only)
97
+
98
+ You must first equip the Flyrb with pastie in your .irbrc:
99
+
100
+ Flyrb.equip(:pastie)
101
+
102
+ This line will also automatically equip the Clipboard, which is required to use pastie.
103
+
104
+ First copy some code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command:
105
+
106
+ pastie
107
+
108
+ or the shortcut version:
109
+
110
+ pst
111
+
112
+ 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.)
113
+
114
+ == Unix-style history buffer
115
+
116
+ 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.
117
+
118
+ == Write command history to file or vi
119
+
120
+ 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".
121
+
122
+ == Grep classes and methods for strings
123
+
124
+ Classes:
125
+
126
+ >> grep_classes("ixnum")
127
+ #=> ["Fixnum"]
128
+
129
+ >> grep_classes("num")
130
+ #=> ["Bignum", "Fixnum", "Numeric", "REXML::SyncEnumerator"]
131
+
132
+ Methods:
133
+
134
+ >> "any arbitrary string".grep_methods("pretty")
135
+ #=> ["pretty_inspect", "pretty_print_instance_variables", "pretty_print_inspect", "pretty_print", "pretty_print_cycle"]
136
+
137
+ >> 32.grep_methods("*")
138
+ #=> ["*", "**"]
139
+
140
+ At some point it'll probably be a good idea to add regex support for these methods.
141
+
142
+ == Verbosity controls for regular IRB and Rails console
143
+
144
+ regular IRB: "verbose" or "v" / "quiet" or "q"
145
+
146
+ Rails: "log" method turns verbosity on, there isn't actually any method for turning it off. (Might add one at some point.)
147
+
148
+ == Finder shortcuts for Rails console
149
+
150
+ user(:all) / user(1)
151
+
152
+ instead of
153
+
154
+ User.find(:all) / User.find(1)
155
+
156
+ Supports arbitrarily complex finds.
157
+
158
+ == Upload shortcut for Amazon S3
159
+
160
+ First, define your secret keys in your environment variables:
161
+
162
+ export AMAZON_ACCESS_KEY_ID='foofoofoofoofoo'
163
+ export AMAZON_SECRET_ACCESS_KEY='barbarbarbarbar'
164
+
165
+ (Obviously, replace those with actual values.)
166
+
167
+ Then, you can use
168
+
169
+ aws_upload("bucket_name","filename")
170
+
171
+ 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 amazon.rubyforge.org for details on that.
172
+
173
+ A good way to use this is actually to have a default bucket, and create a further method in your .irbrc file:
174
+
175
+ def my_bucket_name(filename)
176
+ aws_upload("my_default_bucket",filename)
177
+ end
178
+
179
+ == Command-line Amazon S3 upload script
180
+
181
+ Flyrb also includes amazon, a simple command-line uploader for S3. It requires that you set your Amazon environment variables (see above). The usage is:
182
+
183
+ amazon -b my_bucket_name filename other_filename
184
+
185
+ (For any arbitrary number of filenames.)
186
+
187
+ 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
188
+
189
+ amazon -b blog_files some_file.name
190
+
191
+ Or
192
+
193
+ amazon --bucket blog_files some_file.name
194
+
195
+ 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:
196
+
197
+ alias b1="amazon --bucket my_main_bucket $1"
198
+ alias b2="amazon --bucket my_other_bucket $1"
199
+
200
+ And then you would only have to type:
201
+
202
+ b1 file.name
203
+
204
+ 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.
205
+
206
+ == Command-line Google shortcut (OS X only)
207
+
208
+ To pop open a new window in your default browser with Google search results for a given search term, do:
209
+
210
+ google "any given term"
211
+
212
+ For one-word terms, you can omit the quotes:
213
+
214
+ google term
215
+
216
+ If you already have the search term in your clipboard, you can just type:
217
+
218
+ google
219
+
220
+ (The last approach is useful for unusual command-line error messages.)
221
+
222
+ == Auto-indentation and tab completion
223
+
224
+ 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.)
225
+
226
+ == _ special variable (like Unix shell var !!)
227
+
228
+ 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.
229
+
230
+ 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.
231
+
232
+ == Extremely basic themes for Wirble syntax coloring
233
+
234
+ Flyrb incorporates Wirble as a dependency. Wirble provides syntax coloring. Flyrb 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:
235
+
236
+ Flyrb::Themes.background(:light)
237
+
238
+ To revert back to the default, just use this:
239
+
240
+ Flyrb::Themes.background(:dark)
241
+
242
+ To specify an entirely new syntax color scheme, see the source code for this gem or for Wirble.
243
+
244
+ == Pascal/JavaScript-style "with" statement
245
+
246
+ I use this with RSpec's spec_helper. Instead of:
247
+
248
+ Spec::Runner.configure do |config|
249
+ config.use_transactional_fixtures = true
250
+ config.use_instantiated_fixtures = false
251
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures'
252
+ config.mock_with :flexmock
253
+ end
254
+
255
+ I do this:
256
+
257
+ Spec::Runner.configure do |config|
258
+ with(config) do
259
+ use_transactional_fixtures = true
260
+ use_instantiated_fixtures = false
261
+ fixture_path = RAILS_ROOT + '/spec/fixtures'
262
+ mock_with :flexmock
263
+ end
264
+ end
265
+
266
+ Note however that this blew up once and I have no idea why. Caveat emptor, et cetera.
267
+
268
+ == String#to_proc
269
+
270
+ Syntactic sugar for functional programming.
271
+
272
+ (1..3).map(&'*2') => [2, 4, 6]
273
+ (1..3).map(&'[-1, _, 0]') => [[-1, 1, 0], [-1, 2, 0], [-1, 3, 0]]
274
+ (1..3).map(&'x -> y -> x * y').map(&'[2]') => [2, 4, 6]
275
+ (1..5).select(&'>2') => [3, 4, 5]
276
+ (1..3).map(&'x -> y -> x * y').map(&'.call(2)') => [2, 4, 6]
277
+ [5].map(&"(1.._).inject(&'*')") => [120]
278
+
279
+ For more detail see: http://weblog.raganwald.com/2007/10/stringtoproc.html
280
+
281
+ == Add and subtract Hashes with + and -
282
+
283
+ {:a => :b} + {:c => :d} = {:a => :b, :c => :d}
284
+ {:a => :b, :c => :d} - {:c => :d} = {:a => :b}
285
+ {:a => :b, :c => :d} - :c = {:a => :b}
286
+
287
+ 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.)
288
+
289
+ == Grammatically-correct is_an? method - no more "is_a? Array" statements
290
+
291
+ >> [].is_an? Array
292
+ #=> true
293
+
294
+ Most people don't care, but personally, "is_a? Array" drives me completely insane.
295
+
296
+ == Object#not
297
+
298
+ Replace this:
299
+
300
+ if !response.incomplete? && !response.invalid? && response.total > 0
301
+
302
+ With this:
303
+
304
+ if response.not.incomplete? && response.not.invalid? && response.total > 0
305
+
306
+ Syntactic sugar for boolean conditions.
307
+
308
+ More detail here:
309
+
310
+ http://blog.jayfields.com/2007/08/ruby-adding-not-method-for-readability.html
311
+
312
+ == One-character exit command
313
+
314
+ x
315
+
316
+ Because life is too short to type whole words.
317
+
318
+ == REQUIREMENTS
319
+
320
+ * ReadLine
321
+ * Wirble
322
+ * Amazon S3
323
+ * Platform
324
+ * Some features require OS X
325
+
326
+ == LICENSE
327
+
328
+ (The MIT License)
329
+
330
+ Copyright (c) 2006-2007 Giles Bowkett
331
+ Portions Copyright (c) 2006-2007 Ben Bleything
332
+ Portions Copyright (c) 2006-2007 Reginald Braithwaite
333
+ Portions Copyright (c) 2006-2007 Gregory Brown
334
+ Portions Copyright (c) 2006-2007 Jamis Buck
335
+ Portions Copyright (c) 2006-2007 Mike Clark
336
+ Portions Copyright (c) 2006-2007 Jay Fields
337
+ Portions Copyright (c) 2005 David Heinemeier Hansson
338
+ Portions Copyright (c) 2006-2007 Ara T. Howard
339
+ Portions Copyright (c) 2006-2007 Pat Maddox
340
+ Portions Copyright (c) 2006-2007 Marcel Molina, Jr.
341
+ Portions Copyright (c) 2006-2007 Rick DeNatale
342
+ Portions Copyright (c) 2006-2007 Projectionist (Marcel Molina? Chad Fowler?)
343
+ Portions Copyright (c) 2006-2007 Dan Yoder
344
+
345
+ Permission is hereby granted, free of charge, to any person obtaining
346
+ a copy of this software and associated documentation files (the
347
+ 'Software'), to deal in the Software without restriction, including
348
+ without limitation the rights to use, copy, modify, merge, publish,
349
+ distribute, sublicense, and/or sell copies of the Software, and to
350
+ permit persons to whom the Software is furnished to do so, subject to
351
+ the following conditions:
352
+
353
+ The above copyright notice and this permission notice shall be
354
+ included in all copies or substantial portions of the Software.
355
+
356
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
357
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
358
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
359
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
360
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
361
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
362
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/amazon ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ %w{rubygems platform optparse}.each {|library| require library}
3
+
4
+ # command-line args
5
+ option_parser = OptionParser.new
6
+ option_parser.on("-b", "--bucket NAME", String) {|bucket| @bucket = bucket unless bucket.empty?}
7
+ filenames = option_parser.parse(ARGV)
8
+ abort "Usage: amazon -b bucket_name file_name" unless @bucket && filenames
9
+
10
+ # require files, populate hash
11
+ require 'flyrb'
12
+ Flyrb.equip(:amazon_upload_shortcut)
13
+ include Flyrb::AmazonUploadShortcut
14
+
15
+ # baddabing, baddaboom
16
+ filenames.each {|filename| puts aws_upload(@bucket, filename)}
data/bin/google ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ %w{rubygems platform net/http flyrb}.each {|library| require library}
3
+
4
+ Flyrb.equip(:google)
5
+ include Flyrb::Google
6
+
7
+ google(ARGV[0])
data/bin/pastie ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ %w{rubygems flyrb}.each {|library| require library}
3
+
4
+ Flyrb.equip(:pastie)
5
+ include Flyrb::Pastie
6
+
7
+ pastie(ARGV[0])
data/flyrb.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "flyrb"
3
+ s.version = "1.0.0.a"
4
+ s.author = "John Trupiano"
5
+ s.email = "jtrupiano@gmail.com"
6
+ s.homepage = "http://github.com/jtrupiano/flyrb"
7
+ s.rubyforge_project = "flyrb"
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "A grab-bag of IRB power user madness (originaly Giles Bowkett's flyrb)."
10
+ 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/flyrb", "lib/flyrb/amazon_upload_shortcut.rb", "lib/flyrb/clipboard.rb", "lib/flyrb/command_history.rb", "lib/flyrb/convertable_to_file.rb", "lib/flyrb/equipper.rb", "lib/flyrb/google.rb", "lib/flyrb/hash_math.rb", "lib/flyrb/interactive_editor.rb", "lib/flyrb/irb_options.rb", "lib/flyrb/irb_verbosity_control.rb", "lib/flyrb/is_an.rb", "lib/flyrb/language_greps.rb", "lib/flyrb/not.rb", "lib/flyrb/pastie.rb", "lib/flyrb/pipe.rb", "lib/flyrb/rails_finder_shortcut.rb", "lib/flyrb/rails_verbosity_control.rb", "lib/flyrb/string_to_proc.rb", "lib/flyrb/symbol_to_proc.rb", "lib/flyrb/wirble.rb", "lib/flyrb/with.rb", "lib/flyrb.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/flyrb_spec.rb", "flyrb.gemspec"]
11
+ %w{amazon google pastie}.each do |command_line_utility|
12
+ s.executables << command_line_utility
13
+ end
14
+ s.require_path = "lib"
15
+ s.test_file = "spec/flyrb_spec.rb"
16
+ s.has_rdoc = true
17
+ s.extra_rdoc_files = ["README"]
18
+ s.add_dependency("activesupport")
19
+ s.add_dependency("wirble", ">= 0.1.2")
20
+ s.add_dependency("aws-s3", ">= 0.4.0")
21
+ s.add_dependency("Platform", ">= 0.4.0")
22
+ end