alkesh-gemedit 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ == 0.0.2 2008-03-07
2
+
3
+ * 1 minor enhancement:
4
+ * add -p/--pretend option to show what gem(s) would be edited and with what command
5
+
6
+ == 0.0.1 2008-02-27
7
+
8
+ * 1 major enhancement:
9
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Lee Marlow
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ gemedit
2
+ http://gemedit.rubyforge.org/
3
+ by Lee Marlow
4
+
5
+ == DESCRIPTION:
6
+
7
+ Gemedit lets you quickly open up the source for a gem in your favorite editor.
8
+
9
+ Looking through other people's code is a great way to learn. I often use it when a gem's RDoc isn't as helpful as I'd like or just want to see how someone put a library together. Gemedit just makes it easier to get to the code.
10
+
11
+ == INSTALLATION:
12
+
13
+ Gemedit can be installed via RubyGems:
14
+
15
+ $ sudo gem install gemedit
16
+
17
+ If you would like some basic command completion for installed gems add the following to your ~/.bashrc or ~/.profile:
18
+
19
+ complete -C "/usr/bin/gemedit --complete" gemedit
20
+
21
+ == USAGE:
22
+
23
+ If you want to see how gemedit works just install it and run this:
24
+ $ gemedit gemedit
25
+
26
+ Gemedit tries to use your favorite editor from your <tt>$VISUAL</tt> or <tt>$EDITOR</tt> environment variable. It will fall back to <em>everyone's</em> favorite editor: *vi*. You can specify the editor with the <tt>-e/--editor</tt> switch. Run this to view the source for +rake+ in TextMate[http://macromates.com]:
27
+ $ gemedit -e mate rake
28
+
29
+ And of course, help is available:
30
+ $ gemedit -h
31
+ $ gemedit --help
32
+
33
+ == DOCUMENTATION:
34
+
35
+ There isn't much more to document than what is on this page, but feel free to browse the RDoc[http://gemedit.rubyforge.org/rdoc/]. Or checkout the Rubyforge project page here[http://rubyforge.org/projects/gemedit/].
36
+
37
+ == SOURCE REPOSITORY:
38
+
39
+ The source is currently on github[http://github.com/]. You can browse through it at http://github.com/lmarlow/gemedit or pull it down and play with it yourself with
40
+
41
+ $ git clone git://github.com/lmarlow/gemedit.git
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-2-27.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ require 'optparse'
13
+
14
+ OPTIONS = {
15
+ :verbose => false,
16
+ :pretend => false,
17
+ :editor => ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
18
+ }
19
+
20
+ parser = OptionParser.new do |opts|
21
+ opts.banner = <<BANNER
22
+ Open the source of installed gems in your favorite editor
23
+
24
+ Usage: #{File.basename($0)} GEM_NAME...
25
+
26
+ Options are:
27
+ BANNER
28
+ opts.on("-e", "--editor=EDITOR", String,
29
+ "The editor to open the gems with", "Default: #{OPTIONS[:editor]}") { |editor| OPTIONS[:editor] = editor }
30
+ opts.on("-p", "--pretend",
31
+ "Shows what command would be run without running it", "Turns on verbose logging", "Default: #{OPTIONS[:pretend]}") { |pretend|
32
+ OPTIONS[:pretend] = OPTIONS[:verbose] = true
33
+ }
34
+ opts.on("-v", "--verbose",
35
+ "Enable verbose logging", "Default: #{OPTIONS[:verbose]}") { |verbose| OPTIONS[:verbose] = true }
36
+ opts.on("-h", "--help",
37
+ "Show this help message.") { puts opts; exit }
38
+ end
39
+
40
+ if ARGV.include?('--complete')
41
+ exit 0 unless /\b#{Regexp.escape(File.basename($0))}\b/ =~ ENV["COMP_LINE"]
42
+ after_match = $'
43
+ complete_term = (after_match.empty? || after_match =~ /\s$/) ? nil : after_match.split.last
44
+ completions = if complete_term =~ /\A-/
45
+ parser.top.list.select { |opt| OptionParser::Switch === opt }.inject([]) { |ary, opt|
46
+ ary + opt.short + opt.long
47
+ }.select { |opt_string| opt_string =~ /\A#{Regexp.escape(complete_term)}/ }
48
+ elsif complete_term
49
+ Gem.source_index.inject([]) { |ary, (full_name, spec)| ary << full_name if /^#{Regexp.escape(complete_term)}/i =~ full_name; ary }
50
+ else
51
+ Gem.source_index.map { |full_name, spec| full_name }
52
+ end
53
+ puts completions
54
+ exit 0
55
+ end
56
+
57
+ parser.parse!(ARGV)
58
+
59
+ def get_gem(gem_name)
60
+ possible_gems = Gem.source_index.inject([]) { |ary, (name, spec)| ary << spec if /^#{Regexp.escape(gem_name)}/i =~ spec.full_name; ary }.sort_by { |gem| gem.version }.reverse
61
+ if possible_gems.size < 1
62
+ puts "No gems found for #{gem_name}... skipping"
63
+ end
64
+ gem = possible_gems.first if possible_gems.map { |g| g.name }.uniq.size == 1
65
+ gem ||= begin
66
+ require 'rubygems/user_interaction'
67
+ include Gem::DefaultUserInteraction
68
+ list = possible_gems.map { |g| "#{g.name} #{g.version}" }
69
+ list << 'None of the above'
70
+ name, index = ui.choose_from_list("Choose which gem to view for '#{gem_name}':", list)
71
+ possible_gems[index] if (0...possible_gems.size).include?(index)
72
+ end
73
+ gem
74
+ end
75
+
76
+ gems = ARGV.reject { |arg| arg.empty? }.map { |gem_name| get_gem(gem_name) }.compact
77
+
78
+ if gems.size > 0
79
+ puts "Opening the following gems with #{OPTIONS[:editor]}:" if OPTIONS[:verbose]
80
+ paths = gems.map do |gem|
81
+ puts " #{gem.full_name}: #{gem.full_gem_path}" if OPTIONS[:verbose]
82
+ %Q{"#{gem.full_gem_path}"}
83
+ end
84
+ cmd = "#{OPTIONS[:editor]} #{paths.join(' ')}"
85
+ puts "Running `#{cmd}`" if OPTIONS[:verbose]
86
+ exec cmd unless OPTIONS[:pretend]
87
+ else
88
+ puts "No gems found for editing"
89
+ end
90
+ exit 0
@@ -0,0 +1,5 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ module Gemedit
4
+
5
+ end
@@ -0,0 +1,9 @@
1
+ module Gemedit #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 2
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alkesh-gemedit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Lee Marlow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-26 00:00:00 -07:00
13
+ default_executable: gemedit
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.0
24
+ version:
25
+ description: A utility to view a gem's source in your favorite editor
26
+ email:
27
+ - lmarlow@rubyforge.org
28
+ executables:
29
+ - gemedit
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - License.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - License.txt
39
+ - README.txt
40
+ - bin/gemedit
41
+ - lib/gemedit.rb
42
+ - lib/gemedit/version.rb
43
+ has_rdoc: false
44
+ homepage: http://gemedit.rubyforge.org
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --main
48
+ - README.txt
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: gemedit
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A utility to view a gem's source in your favorite editor
70
+ test_files: []
71
+