Module: Zerg::Support::Gems

Defined in:
lib/zerg_support/gems.rb

Overview

methods used in gem installation hooks

Class Method Summary collapse

Class Method Details

.emulate_extension_install(extension_name) ⇒ Object

tricks rubygems into believeing that the extension compiled and worked out



50
51
52
53
54
55
56
57
58
59
# File 'lib/zerg_support/gems.rb', line 50

def self.emulate_extension_install(extension_name)
  File.open('Makefile', 'w') { |f| f.write "all:\n\ninstall:\n\n" }
  File.open('make', 'w') do |f|
    f.write '#!/bin/sh'
    f.chmod f.stat.mode | 0111
  end
  File.open(extension_name + '.so', 'w') {}
  File.open(extension_name + '.dll', 'w') {}
  File.open('nmake.bat', 'w') { |f| }
end

.ensure_on_path(bin_script) ⇒ Object

ensures that bin_file can be invoked from a shell



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/zerg_support/gems.rb', line 36

def self.ensure_on_path(bin_script)
  caller_trace = Kernel.caller.first
  caller_match = /^(.*)\:\d+\:in /.match(caller_trace) ||
                 /^(.*)\:\d+$/.match(caller_trace)
  bin_file = File.expand_path caller_match[1] + '/../../../bin/' + bin_script
  # this is a cheat to get the binary in the right place on stubborn Debians
  if RUBY_PLATFORM =~ /win/ and RUBY_PLATFORM !~ /darwin/
    ensure_on_windows_path bin_file
  else
    ensure_on_unix_path bin_file
  end
end

.ensure_on_unix_path(bin_file) ⇒ Object

called by ensure_on_path for UNIX systems



24
25
26
27
28
29
30
31
32
33
# File 'lib/zerg_support/gems.rb', line 24

def self.ensure_on_unix_path(bin_file)
  path = "/usr/bin/#{File.basename bin_file}"
  begin
    # using a link so the gem can be updated and the link still works
    FileUtils.ln_s(bin_file, path, :force)
  rescue
    # if anything goes wrong we probably don't have permissions
    # oh well at least we tried
  end
end

.ensure_on_windows_path(bin_file) ⇒ Object

called by ensure_on_path for Windows systems



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zerg_support/gems.rb', line 4

def self.ensure_on_windows_path(bin_file)
  bat_file = File.expand_path(File.join(ENV["WINDIR"],
                              File.basename(bin_file) + ".bat"))
  begin
    File.open(bat_file, 'w') do |f|
      f.write <<END_BATCH
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "#{File.expand_path(bin_file)}" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"ruby.exe" "#{File.expand_path(bin_file)}" %*
END_BATCH
    end
  #rescue
    # if anything goes wrong we probably don't have permissions (hi Vista?)
  end    
end