gem-init 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,101 @@
1
+ require 'rest-client'
2
+
3
+ class Gem::Commands::InitCommand < Gem::Command
4
+
5
+ def initialize
6
+ super 'init', 'Create the barebones of a rubygem'
7
+
8
+ add_option('-s', '--skip-check', 'Skip check to see if gem already exists') do |value, options|
9
+ options[:skip_check] = true
10
+ end
11
+
12
+ end
13
+
14
+ def execute
15
+ gem_name = get_one_optional_argument
16
+
17
+ gem_exists = options[:skip_check].nil? ? gem_exists?(gem_name) : false
18
+
19
+ if gem_exists
20
+ say "That gem already exists on rubygems.org! Find a new name or use the -s option to skip the check"
21
+ else
22
+ create_gemspec(gem_name)
23
+ create_ruby_file(gem_name)
24
+ create_rakefile
25
+ end
26
+ end
27
+
28
+ def gem_exists?(gem_name)
29
+ response = RestClient.get("http://rubygems.org/api/v1/gems/#{gem_name}.json") do |response, request, result|
30
+ if response.code == 404
31
+ return false
32
+ else
33
+ return true
34
+ end
35
+ end
36
+ end
37
+
38
+ def create_gemspec(gem_name)
39
+ File.open("#{gem_name}.gemspec", 'w+') do |f|
40
+ f.puts <<-GEMSPEC
41
+ Gem::Specification.new do |s|
42
+ s.name = "#{gem_name}"
43
+ s.version = '0.0.1'
44
+ s.authors = ["YOURNAME"]
45
+ s.email = "TODO YOUREMAIL"
46
+ s.homepage = "TODO HOMEPAGE"
47
+ s.summary = "TODO SUMMARY"
48
+ s.description = "TODO DESCRIPTION"
49
+ s.required_rubygems_version = ">= 1.3.6"
50
+ s.files = ['lib/rubygems_plugin.rb']
51
+ end
52
+ GEMSPEC
53
+ end
54
+ end
55
+
56
+ def create_ruby_file(gem_name)
57
+ Dir.mkdir("lib")
58
+ File.open("lib/#{gem_name}.rb", 'w+') do |f|
59
+ f.puts <<-FILE
60
+ class #{gem_name.capitalize}
61
+ end
62
+ FILE
63
+ end
64
+ end
65
+
66
+ def create_rakefile
67
+ Dir.mkdir("test")
68
+ File.open("Rakefile", 'w+') do |f|
69
+ f.puts <<-RAKEFILE
70
+ require 'rake/testtask'
71
+
72
+ Rake::TestTask.new do |t|
73
+ t.libs << 'test'
74
+ end
75
+
76
+ desc "Run tests"
77
+ tas :default => :test
78
+ RAKEFILE
79
+ end
80
+ end
81
+
82
+ def arguments # :nodoc:
83
+ "NAME name of your new rubygem"
84
+ end
85
+
86
+ def usage # :nodoc:
87
+ "#{program_name} NAME"
88
+ end
89
+
90
+ # def defaults_str # :nodoc:
91
+ # "--local --columns name,summary,author --fields name --no-installed"
92
+ # end
93
+
94
+ # def description # :nodoc:
95
+ # 'Enhances search command by providing options to search (--fields) and display (--columns) ' +
96
+ # 'gemspec attributes. Results are displayed in an ascii table. Gemspec attributes can be specified '+
97
+ # 'by the first unique string that it starts with i.e. "su" for "summary". To specify multiple gemspec attributes, delimit ' +
98
+ # "them with commas. Gemspec attributes available to options are: #{self.class.valid_gemspec_columns.join(', ')}."
99
+ # end
100
+
101
+ end
@@ -0,0 +1,4 @@
1
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.3.6')
2
+ require 'rubygems/command_manager'
3
+ Gem::CommandManager.instance.register_command(:init)
4
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-init
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Marshall Huss
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: description
35
+ email: mwhuss@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/rubygems_plugin.rb
44
+ - lib/rubygems/commands/init_command.rb
45
+ homepage: http://github.com/mwhuss/git-init
46
+ licenses:
47
+ - MIT
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 23
68
+ segments:
69
+ - 1
70
+ - 3
71
+ - 6
72
+ version: 1.3.6
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.7.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: summary
80
+ test_files: []
81
+