Module: Excavator

Defined in:
lib/excavator.rb,
lib/excavator.rb,
lib/excavator/dsl.rb,
lib/excavator/param.rb,
lib/excavator/runner.rb,
lib/excavator/command.rb,
lib/excavator/version.rb,
lib/excavator/namespace.rb,
lib/excavator/table_view.rb,
lib/excavator/environment.rb,
lib/excavator/param_parser.rb

Overview

Excavator automatically creates a command line parser for your params as well as building a simple usage and option messages for your scripts.

Defined Under Namespace

Modules: DSL Classes: Command, Environment, ExcavatorError, MissingParamsError, Namespace, Param, ParamParser, Runner, TableView

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.config(name, default) ⇒ Object

Internal: Setup class level configuration variables with defaults.

Examples

module Excavator
  config :test, "test"
end

Excavator.test
# => "test"

Excavator.test = "123"
Excavator.test
# => "123"

Returns nothing.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/excavator.rb', line 86

def self.config(name, default)
  @config   ||= {}
  @defaults ||= {}
  @defaults[name.to_sym] = default
  module_eval <<-MOD, __FILE__, __LINE__  + 1
    def self.#{name}
      @config[:#{name}] || @defaults[:#{name}]
    end

    def self.#{name}=(val)
      @config[:#{name}] = val
    end
  MOD
end

.cwdObject

Public: The current working directory for the Excavator script.

Returns a Pathname.



21
22
23
# File 'lib/excavator.rb', line 21

def self.cwd
  @cwd ||= Pathname.new(Dir.pwd).expand_path
end

.reset!Object

Internal: Resets the global Runner object. This is primarily used in testing.

Examples

Excavator.reset!

Returns nothing.



109
110
111
# File 'lib/excavator.rb', line 109

def self.reset!
  self.runner = nil
end

.run(params) ⇒ Object

Public: Start Excavator.

On command error, this method will exit with a status of 1 and print the error message to $stderr.

params - An Array of parameters. This is normally ARGV.

Examples

Excavator.run(ARGV)
# => executes command passed in via ARGV

Returns the object returned to by the command or exits with a status of 1.



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/excavator.rb', line 56

def self.run(params)
  begin
    runner.run(params)

  rescue => e
    $stderr.puts e.message
    if ENV['DEBUG'] == '1'
      e.backtrace.each { |line| $stderr.puts line }
    end

    exit 1
  end
end

.runnerObject

Public: The global Runner object. This object is called from Excavator.run to start the whole command loading, commandline parsing and command execution process.

Returns a Runner class.



31
32
33
# File 'lib/excavator.rb', line 31

def self.runner
  @runner ||= runner_class.new
end

.runner=(runner) ⇒ Object

Public: The global Runner assignment method.

runner - Any Class that implements Excavator::Runner’s public api.



39
40
41
# File 'lib/excavator.rb', line 39

def self.runner=(runner)
  @runner = runner
end