flyrb 1.0.0.a → 1.0.0.b

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -4,11 +4,11 @@ previously utility_belt by Giles Bowkett (and many others): http://utilitybelt.r
4
4
 
5
5
  == Why Hijack The Project?
6
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.
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 for myself and others.
8
8
 
9
9
  == Why Rename It?
10
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.
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
12
 
13
13
  == DESCRIPTION
14
14
 
@@ -24,6 +24,7 @@ sudo gem install flyrb
24
24
 
25
25
  * Interactively edit IRB code in your preferred text editor
26
26
  * Read from and write to OS X clipboard
27
+ * Gist your code with one command
27
28
  * Post your code to Pastie with one command (OS X only)
28
29
  * Kick-ass Unix-style history buffer
29
30
  * Write command history to file or vi
@@ -79,7 +80,7 @@ or
79
80
 
80
81
  If you're wondering why the method name is so ridiculously long, there's a story there:
81
82
 
82
- http://gilesbowkett.blogspot.com/2007/12/flyrb-vs-rails.html
83
+ http://gilesbowkett.blogspot.com/2007/12/utility-belt-vs-rails.html
83
84
 
84
85
  == Read from and write to OS X or Windows clipboard
85
86
 
@@ -93,9 +94,25 @@ To write:
93
94
 
94
95
  Clipboard.write("something")
95
96
 
97
+ == Gist your code
98
+
99
+ You must first equip Flyrb with gist in your .irbrc:
100
+
101
+ Flyrb.equip(:gist)
102
+
103
+ This line will also automatically equip the Clipboard, which is required to use gist.
104
+
105
+ First copy come code into your clipboard, or put it there with the Clipboard.write() class method. Then use the command:
106
+
107
+ gist
108
+
109
+ Note that this method currently also sets the gist filename to fly.rb which triggers Ruby syntax highlighting in your gist. The optional second argument to gist is a filename which GitHub will interpret for syntax highlighting.
110
+
111
+ gist 'PS1=\[\033[0;36m\]\w\[\033[0;33m\]$(parse_git_branch)\[\033[0;36m\] $> \[\033[0;37m\]', ".profile"
112
+
96
113
  == Post your code to Pastie with one command (OS X and Windows only)
97
114
 
98
- You must first equip the Flyrb with pastie in your .irbrc:
115
+ You must first equip Flyrb with pastie in your .irbrc:
99
116
 
100
117
  Flyrb.equip(:pastie)
101
118
 
@@ -327,7 +344,8 @@ Because life is too short to type whole words.
327
344
 
328
345
  (The MIT License)
329
346
 
330
- Copyright (c) 2006-2007 Giles Bowkett
347
+ Copyright (c) 2010 John Trupiano
348
+ Portions Copyright (c) 2006-2007 Giles Bowkett
331
349
  Portions Copyright (c) 2006-2007 Ben Bleything
332
350
  Portions Copyright (c) 2006-2007 Reginald Braithwaite
333
351
  Portions Copyright (c) 2006-2007 Gregory Brown
data/flyrb.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "flyrb"
3
- s.version = "1.0.0.a"
3
+ s.version = "1.0.0.b"
4
4
  s.author = "John Trupiano"
5
5
  s.email = "jtrupiano@gmail.com"
6
6
  s.homepage = "http://github.com/jtrupiano/flyrb"
7
7
  s.rubyforge_project = "flyrb"
8
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"]
9
+ s.summary = "A grab-bag of IRB power user madness (originaly Giles Bowkett's utility_belt)."
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/gist.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", "README", "spec", "spec/convertable_to_file_spec.rb", "spec/equipper_spec.rb", "spec/gist_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
11
  %w{amazon google pastie}.each do |command_line_utility|
12
12
  s.executables << command_line_utility
13
13
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.has_rdoc = true
17
17
  s.extra_rdoc_files = ["README"]
18
18
  s.add_dependency("activesupport")
19
- s.add_dependency("wirble", ">= 0.1.2")
19
+ s.add_dependency("wirble", ">= 0.1.3")
20
20
  s.add_dependency("aws-s3", ">= 0.4.0")
21
21
  s.add_dependency("Platform", ">= 0.4.0")
22
22
  end
@@ -54,12 +54,19 @@ module Flyrb
54
54
  args.each do |arg|
55
55
  gadget = arg.to_s
56
56
 
57
- # Silently ignore unkown gadgets
58
- gadgets_to_equip << gadget if GADGETS.include? gadget
57
+ if GADGETS.include? gadget
58
+ gadgets_to_equip << gadget
59
+ else
60
+ # Don't silently ignore unkown gadgets
61
+ puts "Failed to find gadget #{gadget}, ignoring"
62
+ end
59
63
  end
60
64
  end
61
65
 
62
- gadgets_to_equip.each{|gadget| require "flyrb/#{gadget}" }
66
+ gadgets_to_equip.each{|gadget|
67
+ puts "enabling #{gadget}"
68
+ require "flyrb/#{gadget}"
69
+ }
63
70
 
64
71
  @equipped ||= true
65
72
  end
data/lib/flyrb/gist.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'flyrb'
2
+ require 'open-uri'
3
+ require 'net/http'
4
+
5
+ Flyrb.equip(:clipboard)
6
+
7
+ module Flyrb
8
+ module Gist
9
+ def gist(content = nil, filename = nil)
10
+ content ||= Clipboard.read if Clipboard.available?
11
+ filename ||= "fly.rb"
12
+
13
+ url = URI.parse('http://gist.github.com/gists')
14
+ req = Net::HTTP.post_form(url, data(filename, "rb", content))
15
+
16
+ gist_url = req['Location']
17
+ Clipboard.write(gist_url) if Clipboard.available?
18
+ open(gist_url)
19
+ end
20
+
21
+ private
22
+ def open(url)
23
+ case Platform::IMPL
24
+ when :macosx
25
+ Kernel.system("open #{url}")
26
+ when :mswin
27
+ pastie_url = url.chop if url[-1].chr == "\000"
28
+ Kernel.system("start #{url}")
29
+ end
30
+ end
31
+
32
+ def data(filename, ext, content)
33
+ {
34
+ :'file_ext[gistfile1]' => ext,
35
+ :'file_name[gistfile1]' => filename,
36
+ :'file_contents[gistfile1]' => content
37
+ }.merge(auth)
38
+ end
39
+
40
+ def auth
41
+ user = `git config --global github.user`.strip
42
+ token = `git config --global github.token`.strip
43
+
44
+ user.empty? ? {} : { :login => user, :token => token }
45
+ end
46
+ end
47
+ end
48
+
49
+ class Object
50
+ include Flyrb::Gist
51
+ end if Object.const_defined? :IRB
data/spec/gist_spec.rb ADDED
@@ -0,0 +1,110 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ Platform = Module.new unless Object.const_defined?('Platform')
4
+ Net = Module.new unless Object.const_defined?('Net')
5
+
6
+ require 'flyrb'
7
+ Flyrb.equip(:gist)
8
+ include Flyrb::Gist
9
+ # don't go to the filesystem for the git credentials
10
+ def auth; {}; end
11
+
12
+ Clipboard = Flyrb::Clipboard unless Object.const_defined?('Clipboard')
13
+
14
+ describe "gist being called" do
15
+
16
+ before(:all) do
17
+ Net::HTTP = mock('HTTP') unless Net.const_defined?('HTTP')
18
+ URI = mock('URI') unless Object.const_defined?('URI')
19
+ Clipboard = mock('clipboard') unless Object.const_defined?('Clipboard')
20
+ end
21
+
22
+ before(:each) do
23
+ @page = mock('page')
24
+ @page.stub!(:[]).with('Location').and_return('foo.html')
25
+ Net::HTTP.stub!(:post_form).and_return(@page)
26
+ URI.stub!(:parse)
27
+ Clipboard.stub!(:read)
28
+ Clipboard.stub!(:write)
29
+ Kernel.stub!(:system)
30
+ end
31
+
32
+ it "should be available in global namespace and not blow-up with default stub/mocking" do
33
+ gist
34
+ end
35
+
36
+ it "should uri-parse the gist uri" do
37
+ URI.should_receive(:parse).with("http://gist.github.com/gists")
38
+ gist
39
+ end
40
+
41
+ it "should pass the uri-parsed result into the post" do
42
+ URI.should_receive(:parse).and_return('a_uri_object')
43
+ Net::HTTP.should_receive(:post_form).with('a_uri_object', anything()).and_return(@page)
44
+ gist
45
+ end
46
+
47
+ it "should call system open on the gist return" do
48
+ @page.should_receive(:[]).with('Location').and_return('returned_url')
49
+ case Platform::IMPL
50
+ when :macosx
51
+ Kernel.should_receive(:system).with("open returned_url")
52
+ when :mswin
53
+ Kernel.should_receive(:system).with("start returned_url")
54
+ end
55
+ gist
56
+ end
57
+
58
+ it "should write resulting url into the clipboard" do
59
+ @page.should_receive(:[]).and_return('returned_url')
60
+ Clipboard.should_receive(:write).with('returned_url')
61
+ gist
62
+ end
63
+
64
+ describe "with no parameter it uses the clipboard" do
65
+ it "should read the clipboard" do
66
+ Clipboard.should_receive(:read)
67
+ gist
68
+ end
69
+
70
+ it "should put the clipboard results in the post to gist" do
71
+ Clipboard.should_receive(:read).and_return('bar')
72
+ Net::HTTP.should_receive(:post_form).with(anything(), {
73
+ :"file_ext[gistfile1]" => "rb",
74
+ :"file_name[gistfile1]" => "fly.rb",
75
+ :"file_contents[gistfile1]" => 'bar'
76
+ }).and_return(@page)
77
+ gist
78
+ end
79
+ end
80
+
81
+ describe "with a parameter instead" do
82
+ #TODO: windows/linux safer now, since no clipboard functionality?
83
+ it "should not even read the clipboard" do
84
+ Clipboard.should_not_receive(:read)
85
+ gist "baz"
86
+ end
87
+
88
+ it "should pass in the parameter instead" do
89
+ Net::HTTP.should_receive(:post_form).with(anything(), {
90
+ :"file_ext[gistfile1]" => "rb",
91
+ :"file_name[gistfile1]" => "fly.rb",
92
+ :"file_contents[gistfile1]" => 'baz',
93
+ }).and_return(@page)
94
+
95
+ gist "baz"
96
+ end
97
+ end
98
+
99
+ describe "with a parameter and a filename" do
100
+ it "should set the filename" do
101
+ Net::HTTP.should_receive(:post_form).with(anything(), {
102
+ :"file_ext[gistfile1]" => "rb",
103
+ :"file_name[gistfile1]" => "lisp.el",
104
+ :"file_contents[gistfile1]" => 'foo',
105
+ }).and_return(@page)
106
+
107
+ gist "foo", "lisp.el"
108
+ end
109
+ end
110
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,3 +6,6 @@ require 'rubygems'
6
6
  # test, NOT from the installed gem.
7
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), ".."))
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
9
+
10
+ gem 'rspec'
11
+ require 'spec'
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flyrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.a
4
+ prerelease: true
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ - b
10
+ version: 1.0.0.b
5
11
  platform: ruby
6
12
  authors:
7
13
  - John Trupiano
@@ -9,49 +15,63 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-27 00:00:00 -05:00
18
+ date: 2010-02-28 00:00:00 -05:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: activesupport
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
23
30
  version: "0"
24
- version:
31
+ type: :runtime
32
+ version_requirements: *id001
25
33
  - !ruby/object:Gem::Dependency
26
34
  name: wirble
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
30
37
  requirements:
31
38
  - - ">="
32
39
  - !ruby/object:Gem::Version
33
- version: 0.1.2
34
- version:
40
+ segments:
41
+ - 0
42
+ - 1
43
+ - 3
44
+ version: 0.1.3
45
+ type: :runtime
46
+ version_requirements: *id002
35
47
  - !ruby/object:Gem::Dependency
36
48
  name: aws-s3
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
40
51
  requirements:
41
52
  - - ">="
42
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ - 4
57
+ - 0
43
58
  version: 0.4.0
44
- version:
59
+ type: :runtime
60
+ version_requirements: *id003
45
61
  - !ruby/object:Gem::Dependency
46
62
  name: Platform
47
- type: :runtime
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
50
65
  requirements:
51
66
  - - ">="
52
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ - 4
71
+ - 0
53
72
  version: 0.4.0
54
- version:
73
+ type: :runtime
74
+ version_requirements: *id004
55
75
  description:
56
76
  email: jtrupiano@gmail.com
57
77
  executables:
@@ -87,6 +107,7 @@ files:
87
107
  - lib/flyrb/irb_options.rb
88
108
  - lib/flyrb/irb_verbosity_control.rb
89
109
  - lib/flyrb/is_an.rb
110
+ - lib/flyrb/gist.rb
90
111
  - lib/flyrb/language_greps.rb
91
112
  - lib/flyrb/not.rb
92
113
  - lib/flyrb/pastie.rb
@@ -98,10 +119,10 @@ files:
98
119
  - lib/flyrb/wirble.rb
99
120
  - lib/flyrb/with.rb
100
121
  - lib/flyrb.rb
101
- - Manifest.txt
102
122
  - README
103
123
  - spec/convertable_to_file_spec.rb
104
124
  - spec/equipper_spec.rb
125
+ - spec/gist_spec.rb
105
126
  - spec/hash_math_spec.rb
106
127
  - spec/interactive_editor_spec.rb
107
128
  - spec/language_greps_spec.rb
@@ -124,20 +145,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
145
  requirements:
125
146
  - - ">="
126
147
  - !ruby/object:Gem::Version
148
+ segments:
149
+ - 0
127
150
  version: "0"
128
- version:
129
151
  required_rubygems_version: !ruby/object:Gem::Requirement
130
152
  requirements:
131
153
  - - ">"
132
154
  - !ruby/object:Gem::Version
155
+ segments:
156
+ - 1
157
+ - 3
158
+ - 1
133
159
  version: 1.3.1
134
- version:
135
160
  requirements: []
136
161
 
137
162
  rubyforge_project: flyrb
138
- rubygems_version: 1.3.5
163
+ rubygems_version: 1.3.6
139
164
  signing_key:
140
165
  specification_version: 3
141
- summary: A grab-bag of IRB power user madness (originaly Giles Bowkett's flyrb).
166
+ summary: A grab-bag of IRB power user madness (originaly Giles Bowkett's utility_belt).
142
167
  test_files:
143
168
  - spec/flyrb_spec.rb
data/Manifest.txt DELETED
@@ -1,7 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.txt
4
- Rakefile
5
- bin/flyrb
6
- lib/flyrb.rb
7
- test/test_flyrb.rb