Class: Detroit::Gem

Inherits:
Tool
  • Object
show all
Includes:
RubyUtils, Standard
Defined in:
lib/detroit-gem.rb

Overview

  • purge

Constant Summary collapse

MANPAGE =

Location of man_page for tool.

File.dirname(__FILE__) + '/../man/detroit-gem.5'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#autospecObject

True or false whether to write gemspec from project metadata (default is ‘false`).



42
43
44
# File 'lib/detroit-gem.rb', line 42

def autospec
  @autospec
end

#gemspecObject

The .gemspec filename (default looks-up ‘.gemspec` or `name.gemspec` file).



39
40
41
# File 'lib/detroit-gem.rb', line 39

def gemspec
  @gemspec
end

#installObject



91
92
93
94
95
96
# File 'lib/detroit-gem.rb', line 91

def install
  return unless install?
  package_files.each do |file|
    sh "gem install --no-rdoc --no-ri #{file}"
  end
end

#pkgdirObject

Package directory (defaults to ‘pkg`). Location of packages. This defaults to Project#pkg.



46
47
48
# File 'lib/detroit-gem.rb', line 46

def pkgdir
  @pkgdir
end

#versionObject (readonly)

Version to release. Defaults to current version.



60
61
62
# File 'lib/detroit-gem.rb', line 60

def version
  @version
end

Instance Method Details

#assemble?(station, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
140
141
142
143
144
# File 'lib/detroit-gem.rb', line 137

def assemble?(station, options={})
  return true if station == :package
  return true if station == :install
  return true if station == :release
  return true if station == :reset
  return true if station == :purge
  return false
end

#buildObject

Create a gem package.



72
73
74
75
76
77
78
# File 'lib/detroit-gem.rb', line 72

def build
  trace "gem build #{gemspec}"
  spec = load_gemspec
  package = ::Gem::Package.build(spec)
  mkdir_p(pkgdir) unless File.directory?(pkgdir)
  mv(package, pkgdir)
end

#install?Boolean

Whether to install the gem (default ‘false`).

Returns:

  • (Boolean)


52
53
54
# File 'lib/detroit-gem.rb', line 52

def install?
  @install
end

#packageObject

Write gemspec if autospec is true and then build the gem.



66
67
68
69
# File 'lib/detroit-gem.rb', line 66

def package
  create_gemspec if autospec   # TODO: should autospec be a generate phase?
  build
end

#prerequisiteObject



33
34
35
36
# File 'lib/detroit-gem.rb', line 33

def prerequisite
  require 'rubygems'
  require 'rubygems/package'
end

#purgeObject

TODO:

This code is a little loose. Can it be more specific about which gem file(s) to remove?

Remove package file(s).



129
130
131
132
133
134
# File 'lib/detroit-gem.rb', line 129

def purge
  package_files.each do |f|
    rm(f)
    report "Removed #{f}"
  end
end

#pushObject

Push gem package to RubyGems.org (a la Gemcutter).



101
102
103
104
105
106
107
108
109
# File 'lib/detroit-gem.rb', line 101

def push
  if package_files.empty?
    report "No .gem packages found for version {version} at #{pkgdir}."
  else
    package_files.each do |file|
      sh "gem push #{file}"
    end
  end
end

#releaseObject

Same as #push.



112
113
114
# File 'lib/detroit-gem.rb', line 112

def release
  push
end

#resetObject

Mark package files as outdated.



117
118
119
120
121
122
# File 'lib/detroit-gem.rb', line 117

def reset
  package_files.each do |f|
    utime(0 ,0, f) 
    report "Reset #{f}"
  end
end

#spec(file = nil) ⇒ String

Convert metadata to a gemspec and write to file.

Parameters:

  • file (String) (defaults to: nil)

    Name of gemspec file (defaults to value of #gemspec).

Returns:

  • (String)

    The file name.



86
87
88
# File 'lib/detroit-gem.rb', line 86

def spec(file=nil)
  create_gemspec(file)
end