module Executable

Executable is a mixin for creating robust, inheritable and reusable command line interfaces.

Constants

Legacy

Variation of Executable which provides basic compatibility with previous versions of Executable. It provides a call method that automatically dispatches to public methods.

Among other uses, Dispatch can be useful for dropping into any class as a quick and dirty way to work with it on the command line.

@since 1.2.0

Public Class Methods

included(base) click to toggle source

When Exectuable is included into a class, the class is also extended by ‘Executable::Doamin`.

# File lib/executable.rb, line 19
def self.included(base)
  base.extend Domain
end
new(settings={}) click to toggle source

Default initializer, simply takes a hash of settings to set attributes via writer methods. Not existant attributes are simply ignored.

# File lib/executable.rb, line 28
def initialize(settings={})
  settings.each do |k,v|
    __send__("#{k}=", v) if respond_to?("#{k}=")
  end
end

Public Instance Methods

call(*args) click to toggle source

Command invocation abstract method.

# File lib/executable.rb, line 39
def call(*args)
  #puts cli.show_help           # TODO: show help instead of error ?
  raise NotImplementedError
end
cli() click to toggle source

Access to underlying Help instance.

# File lib/executable.rb, line 63
def cli
  self.class.cli
end
inspect()
Alias for: to_s
option_missing(opt, argv) click to toggle source

Override option_missing if needed. This receives the name of the option and the remaining arguments list. It must consume any arguments it uses from the begining of the list (i.e. in-place manipulation).

# File lib/executable.rb, line 72
def option_missing(opt, argv)
  raise NoOptionError, opt
end
to_proc() click to toggle source

Convert Executable to Proc object.

# File lib/executable.rb, line 47
def to_proc
  lambda { |*args| call(*args) }
end
to_s() click to toggle source

Output command line help.

# File lib/executable.rb, line 56
def to_s
  self.class.help.to_s  # usage ?
end
Also aliased as: inspect