flooose-gemedit 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/version_option'
3
+
4
+ class Gem::Commands::EditCommand < Gem::Command
5
+
6
+ OPTIONS = {
7
+ :version => Gem::Requirement.default,
8
+ :verbose => false,
9
+ :dryrun => false,
10
+ :git => false,
11
+ :editor => ENV['GEMEDITOR'] || ENV['VISUAL'] || ENV['EDITOR'] || 'vi'
12
+ }
13
+
14
+ include Gem::VersionOption
15
+
16
+ def initialize
17
+ super 'edit', 'Open an installed gem in your favorite editor', OPTIONS
18
+
19
+ add_version_option
20
+
21
+ add_option('-e', '--editor EDITOR', String,
22
+ 'The editor to use to open the gems',
23
+ 'GEMEDITOR, VISUAL and EDITOR environment variables',
24
+ 'are used to find the default',
25
+ "Default: #{OPTIONS[:editor]}") do |editor, options|
26
+ options[:editor] = editor
27
+ end
28
+
29
+ add_option('-g', '--git',
30
+ 'Create a git repository in gem directory and do an',
31
+ 'initial commit to help keep track of subsequent',
32
+ 'changes.',
33
+ "Default: #{OPTIONS[:git]}") do |git, options|
34
+ if(git?)
35
+ options[:git] = git
36
+ else
37
+ puts "It doesn't appear that git is installed. If you're sure it's installed please check your $PATH"
38
+ end
39
+ end
40
+
41
+ add_option('-d', '--[no-]dry-run',
42
+ 'Shows what command would be run without running it',
43
+ 'Turns on verbose logging', "Default: #{OPTIONS[:dryrun]}") do |dryrun, options|
44
+ Gem.configuration.verbose ||= true if dryrun
45
+ options[:dryrun] = dryrun
46
+ end
47
+ end
48
+
49
+ def arguments # :nodoc:
50
+ "GEMNAME name of gem to open in your favorite editor"
51
+ end
52
+
53
+ def git?
54
+ system("which git")
55
+ end
56
+
57
+ def defaults_str # :nodoc:
58
+ "--version '#{OPTIONS[:version]}' --editor #{OPTIONS[:editor]} --no-dry-run"
59
+ end
60
+
61
+ def usage # :nodoc:
62
+ "#{program_name} [options] GEMNAME [GEMNAME ...]"
63
+ end
64
+
65
+ def execute
66
+ version = options[:version] || OPTIONS[:version]
67
+
68
+ gem_specs = get_all_gem_names.map { |gem_name|
69
+ if spec = Gem.source_index.find_name(gem_name, version).last
70
+ say "Found gem for '#{gem_name}' with version #{version}" if Gem.configuration.verbose
71
+ else
72
+ say "No gem found for '#{gem_name}' with version #{version}" if Gem.configuration.verbose
73
+ end
74
+ spec
75
+ }.compact
76
+
77
+ if gem_specs.size > 0
78
+ say "Opening the following gems with #{options[:editor]}:" if Gem.configuration.verbose
79
+ paths = gem_specs.map do |spec|
80
+ say " #{spec.full_name} #{spec.full_gem_path}" if Gem.configuration.verbose
81
+ %Q{"#{spec.full_gem_path}"}
82
+ end
83
+ say "Initializing empty git repository in #{paths}" if Gem.configuration.verbose
84
+ paths.each{|path| system('git init #{path}')} if options[:git]
85
+ say "Creating initial commit" if Gem.configuration.verbose
86
+ paths.each{|path| system("cd #{path} && git add ./ && git commit -m 'Gemedit generated commit'")} if options[:git]
87
+ cmd = "#{options[:editor]} #{paths.join(' ')}"
88
+ say "Running `#{cmd}`" if Gem.configuration.verbose
89
+ exec cmd unless options[:dryrun]
90
+ else
91
+ say "No gems found for #{get_all_gem_names.join(', ')}"
92
+ raise Gem::SystemExitException, 1
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ module Gemedit #:nodoc:
2
+ module VERSION #:nodoc:
3
+ VERSION = "0.10.0"
4
+ end
5
+ end
data/lib/gemedit.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'gemedit/edit_command'
3
+
4
+ module Gemedit
5
+
6
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ require 'gemedit'
4
+ Gem::CommandManager.instance.register_command :edit
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flooose-gemedit
3
+ version: !ruby/object:Gem::Version
4
+ hash: 55
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 10
9
+ - 0
10
+ version: 0.10.0
11
+ platform: ruby
12
+ authors:
13
+ - !binary |
14
+ Y2hyaXMgZmzDtsOf
15
+
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2010-10-19 00:00:00 +02:00
21
+ default_executable:
22
+ dependencies: []
23
+
24
+ description: Initialize and make a first commit before editing gem
25
+ email: skeptikos@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - lib/gemedit.rb
34
+ - lib/gemedit/edit_command.rb
35
+ - lib/gemedit/version.rb
36
+ - lib/rubygems_plugin.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/flooose/flooose-gemedit
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: "[none]"
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: gemedit with git functionality
71
+ test_files: []
72
+