Class: GemBuilderLib

Inherits:
Object
  • Object
show all
Defined in:
lib/gembuilderlib.rb,
lib/gembuilder/version.rb

Constant Summary collapse

OBJEXT =
".#{Config::CONFIG["OBJEXT"]}"
VERSION =
'1.2.2'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem) ⇒ GemBuilderLib

Returns a new instance of GemBuilderLib.



24
25
26
27
28
# File 'lib/gembuilderlib.rb', line 24

def initialize(gem)
  @gem_name = gem
  @installer = Gem::Installer.new(@gem_name)
  @format = Gem::Format.from_file_by_path(@gem_name)
end

Class Method Details

.[](gem, conservative = false) ⇒ Object

Helper that will do it all



15
16
17
18
19
20
21
22
# File 'lib/gembuilderlib.rb', line 15

def self.[](gem,conservative=false)
  gem_builder = GemBuilderLib.new(gem)
  gem_builder.unpack_gem
  gem_builder.build_extensions
  gem_builder.fix_gemspec(conservative)
  gem_builder.build_gem
  gem_builder.cleanup
end

Instance Method Details

#build_extensionsObject



52
53
54
# File 'lib/gembuilderlib.rb', line 52

def build_extensions
  installer.build_extensions
end

#build_gemObject



76
77
78
79
80
81
82
83
# File 'lib/gembuilderlib.rb', line 76

def build_gem
  start_dir = Dir.pwd
  Dir.chdir(tmpdir) do
    gb = Gem::Builder.new(spec)
    gb.build
    FileUtils.mv Dir.glob("*.gem"), start_dir
  end
end

#cleanupObject



85
86
87
# File 'lib/gembuilderlib.rb', line 85

def cleanup
  FileUtils.rm_rf(tmpdir)
end

#fix_gemspec(conservative = false) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gembuilderlib.rb', line 63

def fix_gemspec(conservative = false)
  files = []
  Find.find(tmpdir) do |fname|
    next if fname == tmpdir
    next if !conservative && File.extname(fname) == OBJEXT 
    files << fname.sub(Regexp.quote(tmpdir + "/"), '')
  end

  spec.extensions = []
  spec.files += (files - format.spec.files)
  spec.platform = platform
end

#formatObject



38
39
40
# File 'lib/gembuilderlib.rb', line 38

def format
  @format ||= Gem::Format.from_file_by_path(@gem_name)
end

#installerObject



34
35
36
# File 'lib/gembuilderlib.rb', line 34

def installer
  @installer ||= Gem::Installer.new(@gem_name)
end

#platformObject



56
57
58
59
60
61
# File 'lib/gembuilderlib.rb', line 56

def platform
  # I used to use this to clean up gem names under
  # darwin, not sure it was a good idea though
  # Config::CONFIG['arch'].sub(/[\.0-9]*$/, '')
  Config::CONFIG['arch']
end

#specObject



42
43
44
# File 'lib/gembuilderlib.rb', line 42

def spec
  @spec ||= format.spec
end

#tmpdirObject



30
31
32
# File 'lib/gembuilderlib.rb', line 30

def tmpdir
  @tmpdir ||= File.join(Dir.tmpdir, "gembuilder")
end

#unpack_gemObject



46
47
48
49
50
# File 'lib/gembuilderlib.rb', line 46

def unpack_gem
  FileUtils.rm_r(tmpdir) rescue nil
  FileUtils.mkdir_p(tmpdir) rescue nil
  installer.unpack(tmpdir)
end