Class: Gem::Commands::BootstrapCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
CommandOptions, Gem::Commands, GemRelease, Helpers
Defined in:
lib/rubygems/commands/bootstrap_command.rb

Constant Summary collapse

OPTIONS =
{ :gemspec => true, :strategy => 'git', :scaffold => false, :github => false }

Constants included from GemRelease

GemRelease::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBootstrapCommand

Returns a new instance of BootstrapCommand.



12
13
14
15
16
17
18
19
# File 'lib/rubygems/commands/bootstrap_command.rb', line 12

def initialize
  super 'bootstrap', 'Bootstrap a new gem source repository', OPTIONS

  option :gemspec,  '-g', 'Generate a .gemspec'
  option :strategy, '-f', 'Strategy for collecting files [glob|git] in .gemspec'
  option :scaffold, '-s', 'Scaffold lib/[gem_name]/version.rb README test/'
  option :github,   '-h', 'Bootstrap a git repo, create on github and push'
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



10
11
12
# File 'lib/rubygems/commands/bootstrap_command.rb', line 10

def arguments
  @arguments
end

#usageObject (readonly)

Returns the value of attribute usage.



10
11
12
# File 'lib/rubygems/commands/bootstrap_command.rb', line 10

def usage
  @usage
end

Instance Method Details

#create_repoObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rubygems/commands/bootstrap_command.rb', line 69

def create_repo
  options = { :login => github_user, :token => github_token, :name  => gem_name }
  options = options.map { |name, value| "-F '#{name}=#{value}'" }.join(' ')

  say 'Bootstrapializing git repository'
  `git init`

  say 'Staging files'
  `git add .`

  say 'Creating initial commit'
  `git commit -m 'initial commit'`

  say "Adding remote origin [email protected]:#{github_user}/#{gem_name}.git"
  `git remote add origin [email protected]:#{github_user}/#{gem_name}.git`

  say 'Creating repository on Github'
  silence { `curl #{options} http://github.com/api/v2/yaml/repos/create` }

  say 'Pushing to Github'
  `git push origin master`
end

#executeObject



21
22
23
24
25
# File 'lib/rubygems/commands/bootstrap_command.rb', line 21

def execute
  write_gemspec  if options[:gemspec]
  write_scaffold if options[:scaffold]
  create_repo    if options[:github]
end

#write_gemspecObject



27
28
29
# File 'lib/rubygems/commands/bootstrap_command.rb', line 27

def write_gemspec
  GemspecCommand.new.invoke
end

#write_rakefileObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rubygems/commands/bootstrap_command.rb', line 49

def write_rakefile
  if File.exists?('Rakefile')
    say "Skipping Rakefile: already exists"
  else
    rakefile = <<RAKEFILE
require 'rake'
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

task :default => :test
RAKEFILE
    File.open('Rakefile', 'w').write(rakefile)
  end
end

#write_scaffoldObject



31
32
33
34
35
36
37
# File 'lib/rubygems/commands/bootstrap_command.rb', line 31

def write_scaffold
  say 'scaffolding lib/ README test/'
  `mkdir lib test`
  `touch README`
  write_version
  write_rakefile
end

#write_versionObject



39
40
41
42
43
44
45
46
47
# File 'lib/rubygems/commands/bootstrap_command.rb', line 39

def write_version
  version = Version.new(options)
  if File.exists?("#{version.filename}")
    say "Skipping #{version.filename}: already exists"
  else
    say "Creating #{version.filename}"
    version.write
  end
end