Included Modules

Class/Module Index [+]

Quicksearch

Bones::App::Git

Public Class Methods

initialize_git() click to toggle source
# File lib/bones/app/git.rb, line 6
def self.initialize_git
  Bones::App::Create.class_eval {
    include ::Bones::App::Git

    option
    option('Git Options:')
    option('--git', 'Initialize a git repository for the project.',
           lambda { config[:git] = true }
    )
    option('--github DESCRIPTION', 'Create a new GitHub project.',
           'Requires a project description.',
           lambda { |desc|
             config[:git] = true,
             config[:github] = true,
             config[:github_desc] = desc
           }
    )

    in_output_directory :initialize_git, :initialize_github
  }
end

Public Instance Methods

github_url() click to toggle source
# File lib/bones/app/git.rb, line 85
def github_url
  user = Git.global_config['github.user']
  return unless user
  "http://github.com/#{user}/#{name}"
end
initialize_git() click to toggle source
# File lib/bones/app/git.rb, line 28
def initialize_git
  return unless @config[:git]

  File.rename('.bnsignore', '.gitignore') if test ff, '.bnsignore'

  author = Git.global_config['user.name']
  email  = Git.global_config['user.email']

  if test ff, 'Rakefile'
    lines = File.readlines 'Rakefile'

    lines.each do |line|
      case line
      when /^\s*authors\s+/
        line.replace "  authors  '#{author}'" unless author.nil? or line !~ /FIXME/
      when /^\s*email\s+/
        line.replace "  email  '#{email}'" unless email.nil? or line !~ /FIXME/
      when /^\s*url\s+/
        next unless @config[:github]
        url = github_url
        line.replace "  url  '#{url}'" unless url.nil? or line !~ /FIXME/
      when /^\s*\}\s*$/
        line.insert 0, "  ignore_file  '.gitignore'\n" if test ff, '.gitignore'
      end
    end

    File.open('Rakefile', 'w') {|fd| fd.puts lines}
  end

  @git = Git.init
  @git.add
  @git.commit "Initial commit to #{name}."
end
initialize_github() click to toggle source
# File lib/bones/app/git.rb, line 62
def initialize_github
  return unless @config[:github]

  user = Git.global_config['github.user']
  token = Git.global_config['github.token']

  raise ::Bones::App::Error, 'A GitHub username was not found in the global configuration.' unless user
  raise ::Bones::App::Error, 'A GitHub token was not found in the global configuration.' unless token

  Net::HTTP.post_form(
      URI.parse('http://github.com/api/v2/yaml/repos/create'),
      'login' => user,
      'token' => token,
      'name' => name,
      'description' => @config[:github_desc]
  )

  @git.add_remote 'origin', "git@github.com:#{user}/#{name}.git"
  @git.config 'branch.master.remote', 'origin'
  @git.config 'branch.master.merge', 'refs/heads/master'
  @git.push 'origin'
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.