Sha256: ee64d9a9d63cfe5a1894876b56916e4e0a4f89f9b13b9e83baa9b68fa42d65f4

Contents?: true

Size: 1.75 KB

Versions: 5

Compression:

Stored size: 1.75 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, :module_name, :project_name, :author

  def initialize(runtime_args, runtime_options = {})
    super
    usage if args.empty?
    @bin_name     = args.shift
    @module_name  = @bin_name.classify
    @project_name = File.basename(File.expand_path(destination_root))
    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"
      m.directory "lib/#{bin_name}"
      m.directory "test"

      # App stub
      m.template "bin/app.rb.erb", "bin/#{bin_name}"
      m.template "lib/app/cli.rb.erb", "lib/#{bin_name}/cli.rb"
      m.template "test/test_cli.rb.erb", "test/test_#{bin_name}_cli.rb"
    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

5 entries across 5 versions & 1 rubygems

Version Path
newgem-0.29.0 rubygems_generators/executable/executable_generator.rb
newgem-1.0.0 rubygems_generators/executable/executable_generator.rb
newgem-1.0.1 rubygems_generators/executable/executable_generator.rb
newgem-1.0.2 rubygems_generators/executable/executable_generator.rb
newgem-1.0.3 rubygems_generators/executable/executable_generator.rb