Class: Parka::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/parka/cli.rb

Instance Method Summary collapse

Instance Method Details

#build(gemspec_filename = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/parka/cli.rb', line 16

def build(gemspec_filename=nil)
  gemspec  = Gem::Specification.load(gemspec_filename || default_gemspec)
  filename = options[:filename] || "pkg/#{gemspec.file_name}"

  say "Building #{gemspec.file_name}"

  FileUtils.mkdir_p File.dirname(filename)
  Gem::Builder.new(gemspec).build
  FileUtils.mv gemspec.file_name, filename

  filename
end

#install(gemspec_filename = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/parka/cli.rb', line 31

def install(gemspec_filename=nil)
  original_home = ENV["GEM_HOME"]
  gemfile = build(gemspec_filename)
  ENV["GEM_HOME"] = original_home

  system "gem install #{gemfile}"
end

#push(gemspec_filename = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/parka/cli.rb', line 47

def push(gemspec_filename=nil)
  gemspec = Gem::Specification.load(gemspec_filename || default_gemspec)
  gemfile = options[:filename] || build(gemspec_filename)

  # create github remote
  remotes = %x{ git remote }.strip.split("\n")
  unless remotes.include?("github")
    %x{ git remote add github [email protected]:#{github_username}/#{gemspec.name}.git }
  end

  # create github repo
  if options[:create]
    begin
      github["repos/create"].post(
        :name        => gemspec.name,
        :description => gemspec.summary,
        :homepage    => gemspec.homepage,
        :public      => "1"
      )
    rescue
      error "Unable to create GitHub repository: #{gemspec.name}"
    end
  end

  # create release tag
  %x{ git tag v#{gemspec.version} }

  # push to github
  %x{ git push github master --tags }

  # push to rubygems
  pusher = Gem::Commands::PushCommand.new
  pusher.send_gem gemfile
end