Module: RunfileTasks::RubyGems

Extended by:
RubyGems
Included in:
RubyGems
Defined in:
lib/runfile-tasks/rubygems/rubygems.rb

Instance Method Summary collapse

Instance Method Details

#all(gemname, gemdir = "gems") ⇒ Object



7
8
9
10
# File 'lib/runfile-tasks/rubygems/rubygems.rb', line 7

def all(gemname, gemdir="gems")
  build gemname, gemdir
  publish gemname, gemdir
end

#build(gemname, gemdir = "gems") ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/runfile-tasks/rubygems/rubygems.rb', line 12

def build(gemname, gemdir="gems")
  gemver = get_gemver gemname

  command "gem"

  usage  "build [--install]"
  help   "Build gem from gemspec and move it to '#{gemdir}' folder.\nUse --install to also install it."
  action :build do |args|
    say "!txtgrn!Building gem"
    cmd = "gem build #{gemname}.gemspec"  
    say "!txtgrn!Running: !txtpur!#{cmd}"
    system cmd
    say "!txtgrn!Moving gem file to #{gemdir}"
    files = Dir["*.gem"]
    Dir.exist? gemdir or FileUtils.mkdir gemdir
    files.each {|f| FileUtils.mv f, gemdir }
    args['--install'] and execute "gem install"
  end

  usage  "install [--remote]"
  help   "Install gem from local gem file or from rubygems (--remote)."
  action :install do |args|
    if args['--remote']
      cmd = "gem install #{gemname}"
    else
      gemfile = "gems/#{gemname}-#{gemver}.gem"
      cmd = "gem install #{gemfile}"
    end
    say "!txtgrn!Running: !txtpur!#{cmd}"
    system cmd
  end

  endcommand
end

#get_gemver(gemname) ⇒ Object



73
74
75
76
77
# File 'lib/runfile-tasks/rubygems/rubygems.rb', line 73

def get_gemver(gemname)
  spec = Gem::Specification::load "#{gemname}.gemspec"
  spec or abort "Error loading #{gemname}.gemspec"
  spec.version.to_s
end

#publish(gemname, gemdir = "gems") ⇒ 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
# File 'lib/runfile-tasks/rubygems/rubygems.rb', line 47

def publish(gemname, gemdir="gems")
  gemver = get_gemver gemname
  
  command "gem"

  help   "Publish gem to rubygems. Make sure to 'run gem build' before you publish."
  action :publish do
    gemfile = "gems/#{gemname}-#{gemver}.gem"
    File.exist? gemfile or abort "File not found #{gemfile}"
    cmd = "gem push #{gemfile}"
    say "!txtgrn!Running: !txtpur!#{cmd}"
    system cmd
  end

  usage  "yank [VERSION]"
  help   "Yank gem from rubygems."
  action :yank do |args|
    ver = args['VERSION'] || gemver
    cmd = "gem yank #{gemname} -v #{ver}"
    say "!txtgrn!Running: !txtpur!#{cmd}"
    system cmd
  end
  
  endcommand
end