Module: ExecutableHooks::Wrapper

Defined in:
lib/executable-hooks/wrapper.rb

Class Method Summary collapse

Class Method Details

.bindirObject



14
15
16
# File 'lib/executable-hooks/wrapper.rb', line 14

def self.bindir
  Gem.respond_to?(:bindir,true) ? Gem.send(:bindir) : File.join(Gem.dir, 'bin')
end

.destinationObject



17
18
19
# File 'lib/executable-hooks/wrapper.rb', line 17

def self.destination
  File.expand_path( expanded_wrapper_name, bindir )
end

.ensure_custom_shebangObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/executable-hooks/wrapper.rb', line 20

def self.ensure_custom_shebang
  expected_shebang = "$env #{expanded_wrapper_name}"

  Gem.configuration[:custom_shebang] ||= expected_shebang

  if Gem.configuration[:custom_shebang] != expected_shebang
    warn("
Warning:
Found    custom_shebang: '#{Gem.configuration[:custom_shebang]}',
Expected custom_shebang: '#{expected_shebang}',
this can potentially break 'executable-hooks' and gem executables overall!
Check your '~/.gemrc' and '/etc/gemrc' for 'custom_shebang' and remove it.
")
  end
end

.expanded_wrapper_nameObject



11
12
13
# File 'lib/executable-hooks/wrapper.rb', line 11

def self.expanded_wrapper_name
  Gem.default_exec_format % self.wrapper_name
end

.installObject



35
36
37
38
39
40
41
42
43
# File 'lib/executable-hooks/wrapper.rb', line 35

def self.install
  ensure_custom_shebang

  executable_hooks_spec = ExecutableHooks::Specification.find

  if executable_hooks_spec
    install_from( executable_hooks_spec.full_gem_path )
  end
end

.install_from(full_gem_path) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/executable-hooks/wrapper.rb', line 45

def self.install_from(full_gem_path)
  wrapper_path = File.expand_path( "bin/#{wrapper_name}", full_gem_path )

  if File.exist?(wrapper_path) && !File.exist?(destination)
    FileUtils.mkdir_p(bindir) unless File.exist?(bindir)
    # exception based on Gem::Installer.generate_bin
    raise Gem::FilePermissionError.new(bindir) unless File.writable?(bindir)
    FileUtils.cp(wrapper_path, destination)
    File.chmod(0775, destination)
  end
end

.uninstallObject



56
57
58
# File 'lib/executable-hooks/wrapper.rb', line 56

def self.uninstall
  FileUtils.rm_f(destination) if File.exist?(destination)
end

.wrapper_nameObject



8
9
10
# File 'lib/executable-hooks/wrapper.rb', line 8

def self.wrapper_name
  'ruby_executable_hooks'
end