module Rodish::Processor

  1. lib/rodish/processor.rb

Methods

Public Instance

  1. command
  2. freeze
  3. is
  4. on
  5. plugin
  6. process

Attributes

command [R]

The root command for the processor.

Public Instance methods

freeze()

Freeze the command and classes related to the processor when freezing the processor.

[show source]
   # File lib/rodish/processor.rb
65 def freeze
66   command.freeze
67   self::DSL.freeze
68   self::DSL::Command.freeze
69   self::DSL::OptionParser.freeze
70   super
71 end
is(*command_names, command_name, **kw, &block)

Uses the last command name to create a subcommand under the other named commands, with the block being the commands

[show source]
   # File lib/rodish/processor.rb
60 def is(*command_names, command_name, **kw, &block)
61   dsl(command_names).is(command_name, **kw, &block)
62 end
on(*command_names, &block)

Without a block, returns the Command instance for related subcommand (a nested subcommand if multiple command names are given).

With a block, uses the last command name to create a subcommand under the other named commands, configuring the created subcommand using the block.

[show source]
   # File lib/rodish/processor.rb
46 def on(*command_names, &block)
47   if block
48     if command_name = command_names.pop
49       dsl(command_names).on(command_name, &block)
50     else
51       dsl(command_names).instance_exec(&block)
52     end
53   else
54     dsl(command_names)
55   end
56 end
plugin(name, ...)

Load a plugin into the current processor.

[show source]
   # File lib/rodish/processor.rb
12 def plugin(name, ...)
13   mod = load_plugin(name)
14 
15   unless mod.respond_to?(:before_load) || mod.respond_to?(:after_load)
16     _plugin_without_before_or_after_load_check(...)
17   end
18 
19   mod.before_load(self, ...) if mod.respond_to?(:before_load)
20   extend(mod::ProcessorMethods) if defined?(mod::ProcessorMethods)
21   self::DSL.include(mod::DSLMethods) if defined?(mod::DSLMethods)
22   self::DSL::Command.include(mod::CommandMethods) if defined?(mod::CommandMethods)
23   self::DSL::OptionParser.include(mod::OptionParserMethods) if defined?(mod::OptionParserMethods)
24   mod.after_load(self, ...) if mod.respond_to?(:after_load)
25   nil
26 end
process(argv, *a, **kw)

Process an argv array using a new instance of the class that is extended with Rodish::Processor. Additional arguments are passed to new when creating the instance.

Callers of this method are encouraged to rescue Rodish::CommandExit, to handle both early exits and command failures.

[show source]
   # File lib/rodish/processor.rb
34 def process(argv, *a, **kw) 
35   # Deliberately do not pass a block here, to reserve
36   # block handling for future use.
37   @command.process(new(*a, **kw), {}, argv)
38 end