Class: Gem::Commands::BootstrapCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::BootstrapCommand
- Includes:
- CommandOptions, Gem::Commands, GemRelease, Helpers
- Defined in:
- lib/rubygems/commands/bootstrap_command.rb
Constant Summary collapse
- DEFAULTS =
{ :gemspec => true, :strategy => 'git', :scaffold => true, :github => false, :quiet => false }
Constants included from GemRelease
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
- #create_file(template) ⇒ Object
- #create_lib ⇒ Object
- #create_repo ⇒ Object
- #execute ⇒ Object
- #init_git ⇒ Object
-
#initialize(options = {}) ⇒ BootstrapCommand
constructor
A new instance of BootstrapCommand.
- #write_gemspec ⇒ Object
- #write_scaffold ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BootstrapCommand
Returns a new instance of BootstrapCommand.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 18 def initialize( = {}) super 'bootstrap', 'Bootstrap a new gem source repository', DEFAULTS.merge() option :gemspec, '-g', 'Generate a .gemspec' option :scaffold, '-s', 'Scaffold lib/[gem_name]/version.rb README test/' option :strategy, '-f', 'Strategy for collecting files [glob|git] in .gemspec' option :github, '-h', 'Bootstrap a git repo, create on github and push' option :quiet, '-q', 'Do not output status messages' @arguments = "gemname - option name of the gem, will use the current directory if not specified" @usage = "#{program_name} [gemname]" end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
16 17 18 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 16 def arguments @arguments end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
16 17 18 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 16 def usage @usage end |
Instance Method Details
#create_file(template) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 60 def create_file(template) if File.exists?(template.filename) say "Skipping #{template.filename}: already exists" unless quiet? else say "Creating #{template.filename}" unless quiet? template.write end end |
#create_lib ⇒ Object
56 57 58 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 56 def create_lib `mkdir -p lib test` end |
#create_repo ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 74 def create_repo = { :login => github_user, :token => github_token, :name => gem_name } = .map { |name, value| "-F '#{name}=#{value}'" }.join(' ') 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 #{} http://github.com/api/v2/yaml/repos/create` } say 'Pushing to Github' `git push origin master` end |
#execute ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 31 def execute in_bootstrapped_dir do write_scaffold if [:scaffold] write_gemspec if [:gemspec] init_git if [:github] || [:args] # safe to 'git init' in new dir create_repo if [:github] end end |
#init_git ⇒ Object
69 70 71 72 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 69 def init_git say 'Initializing git repository' `git init` end |
#write_gemspec ⇒ Object
40 41 42 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 40 def write_gemspec GemspecCommand.new(:quiet => quiet?).invoke end |
#write_scaffold ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubygems/commands/bootstrap_command.rb', line 44 def write_scaffold say 'scaffolding ...' unless quiet? create_file Template.new('gitignore', :filename => '.gitignore') create_file Template.new('README.md') create_file Template.new('LICENSE', :year => Time.now.year, :author => user_name, :email => user_email) create_file Template.new('Gemfile') create_file Template.new('Rakefile') create_file Template.new('test/test_helper.rb') create_file Version.new() end |