module Executable::Domain

Public Instance Methods

alias_accessor(name, origin) click to toggle source
# File lib/executable/domain.rb, line 62
def alias_accessor(name, origin)
  alias_method "#{name}=", "#{origin}="
  alias_method "#{name}",  "#{origin}"
end
alias_switch(name, origin) click to toggle source
# File lib/executable/domain.rb, line 54
def alias_switch(name, origin)
  alias_method "#{name}=", "#{origin}="
  alias_method "#{name}?", "#{origin}?"
end
attr_switch(name) click to toggle source

Helper method for creating switch attributes.

This is equivalent to:

def name=(val)
  @name = val
end

def name?
  @name
end
# File lib/executable/domain.rb, line 42
def attr_switch(name)
  attr_writer name
  module_eval %{
    def #{name}?
      @#{name}
    end
  }
end
cli()

Interface with cooresponding cli/help object.

Alias for: help
execute(argv=ARGV) click to toggle source

Execute the command.

@param argv [Array] command-line arguments

# File lib/executable/domain.rb, line 98
def execute(argv=ARGV)
  cli, args = parser.parse(argv)
  cli.call(*args)
  return cli
end
Also aliased as: run
help() click to toggle source

Interface with cooresponding cli/help object.

# File lib/executable/domain.rb, line 84
def help
  @help ||= Help.new(self)
end
Also aliased as: cli
inspect() click to toggle source

Inspection method. This must be redefined b/c to_s is overridden.

# File lib/executable/domain.rb, line 70
def inspect
  name
end
parse(argv) click to toggle source

@return [Array<Executable,Array>] The executable and call arguments.

# File lib/executable/domain.rb, line 112
def parse(argv)
  parser.parse(argv)
end
parser() click to toggle source

The parser for this command.

# File lib/executable/domain.rb, line 119
def parser
  @parser ||= Parser.new(self)
end
run(argv=ARGV)

Executables don’t run, they execute! But…

Alias for: execute
subcommands() click to toggle source

Index of subcommands.

@return [Hash] name mapped to subcommnd class

# File lib/executable/domain.rb, line 128
def subcommands
  @subcommands ||= (
    consts = constants - superclass.constants
    consts.inject({}) do |h, c|
      c = const_get(c)
      if Class === c && Executable > c
        n = c.name.split('::').last
        n = n.chomp('Command').chomp('CLI')
        n = n.downcase
        h[n] = c
      end
      h
    end
  )
end
to_s() click to toggle source

Returns ‘help.to_s`.

# File lib/executable/domain.rb, line 77
def to_s
  cli.to_s
end
usage_name() click to toggle source
# File lib/executable/domain.rb, line 7
def usage_name
  list = []
  ancestors.each do |ancestor|
    break if Executable == ancestor
    list.unshift calculate_command_name(ancestor).to_s.strip
  end
  list.reject{|n| n.empty?}.join(" ")
end

Private Instance Methods

calculate_command_name(ancestor) click to toggle source
# File lib/executable/domain.rb, line 17
def calculate_command_name(ancestor)
  if ancestor.methods(false).include?(:command_name)
    command_name.to_s
  else
    cname = ancestor.name.sub(/\#\<.*?\>\:\:/,'').split('::').last.downcase
    cname.chomp('command').chomp('cli')
  end
end