Class: Gem::Micro::BinWrapperEmitter
- Inherits:
-
Object
- Object
- Gem::Micro::BinWrapperEmitter
- Defined in:
- lib/microgem/bin_wrapper_emitter.rb
Instance Method Summary collapse
-
#bin_wrapper_file ⇒ Object
Returns the full path to where the bin wrapper script should be created.
-
#create_bin_wrapper! ⇒ Object
Creates the bin wrapper script in bin_wrapper_file.
-
#initialize(gem_name, bin_name) ⇒ BinWrapperEmitter
constructor
Initializes a new BinWrapperEmitter with a
gem_nameand abin_name. -
#to_ruby ⇒ Object
Returns a string representation of the bin wrapper file.
Constructor Details
#initialize(gem_name, bin_name) ⇒ BinWrapperEmitter
Initializes a new BinWrapperEmitter with a gem_name and a bin_name.
7 8 9 |
# File 'lib/microgem/bin_wrapper_emitter.rb', line 7 def initialize(gem_name, bin_name) @gem_name, @bin_name = gem_name, bin_name end |
Instance Method Details
#bin_wrapper_file ⇒ Object
Returns the full path to where the bin wrapper script should be created. If Ruby was installed with a prefix or suffix it will be inflected and added to the name of the executable.
If the prefix is, for instance, ‘mac’ an executable like macrake will be installed. With a suffix like ‘19’ the name will be rake19.
17 18 19 20 |
# File 'lib/microgem/bin_wrapper_emitter.rb', line 17 def bin_wrapper_file rbconfig('ruby_install_name').match /^(.*)ruby(.*)$/ File.join(Config.bin_dir, "#{$1}#{@bin_name}#{$2}") end |
#create_bin_wrapper! ⇒ Object
Creates the bin wrapper script in bin_wrapper_file.
23 24 25 26 27 |
# File 'lib/microgem/bin_wrapper_emitter.rb', line 23 def create_bin_wrapper! Utils.log(:debug, "Creating bin wrapper `#{bin_wrapper_file}'") File.open(bin_wrapper_file, 'w') { |f| f << to_ruby } File.chmod(0755, bin_wrapper_file) end |
#to_ruby ⇒ Object
Returns a string representation of the bin wrapper file.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/microgem/bin_wrapper_emitter.rb', line 30 def to_ruby %{#!#{ File.join(rbconfig('bindir'), rbconfig('ruby_install_name')) } # # This file was generated by MicroGem (µgem). # # The application '#{@bin_name}' is installed as part of a gem, and # this file is here to facilitate running it. require 'rubygems' version = "> 0" if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then version = $1 ARGV.shift end gem '#{@gem_name}', version load '#{@bin_name}' } end |