Sha256: 5c83f72ddbfbc5dd9a22a28910178ab2645afe8a4c2562ffe6f8625b971b7630

Contents?: true

Size: 1.43 KB

Versions: 10

Compression:

Stored size: 1.43 KB

Contents

class ExecutableGenerator < RubiGen::Base
  DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
                              Config::CONFIG['ruby_install_name'])
  
  default_options :shebang => DEFAULT_SHEBANG,
                  :author => nil
  
  attr_reader :bin_name, :author
  
  def initialize(runtime_args, runtime_options = {})
    super
    usage if args.empty?
    @bin_name     = args.shift
    extract_options
  end

  def manifest
    # Use /usr/bin/env if no special shebang was specified
    script_options     = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
    dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
    windows            = (RUBY_PLATFORM =~ /dos|win32|cygwin/i) || (RUBY_PLATFORM =~ /(:?mswin|mingw)/)

    record do |m|
      # Ensure bin folder exists
      m.directory "bin"

      # App stub
      m.template "app.rb",         "bin/#{bin_name}"
    end
  end

  protected
    def banner
      <<-EOS
Create an executable Ruby script that is deployed
with this RubyGem.

USAGE: #{$0} generate bin_name"
EOS
    end

    def add_options!(opts)
      opts.separator ''
      opts.separator 'Options:'
      opts.on("-a", "--author=\"Your Name\"", String,
              "Generated app file will include your name.",
              "Default: none") { |x| options[:author] = x }
    end
    
    def extract_options
      @author = options[:author]
    end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
newgem-0.19.0 rubygems_generators/executable/executable_generator.rb
newgem-0.20.1 rubygems_generators/executable/executable_generator.rb
newgem-0.21.0 rubygems_generators/executable/executable_generator.rb
newgem-0.19.1 rubygems_generators/executable/executable_generator.rb
newgem-0.20.0 rubygems_generators/executable/executable_generator.rb
newgem-0.23.1 rubygems_generators/executable/executable_generator.rb
newgem-0.22.1 rubygems_generators/executable/executable_generator.rb
newgem-0.22.0 rubygems_generators/executable/executable_generator.rb
newgem-0.23.0 rubygems_generators/executable/executable_generator.rb
newgem-0.22.2 rubygems_generators/executable/executable_generator.rb