Module: Rodish::Processor
- Defined in:
- lib/rodish/processor.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
The root command for the processor.
Instance Method Summary collapse
-
#freeze ⇒ Object
Freeze the command and classes related to the processor when freezing the processor.
-
#is(*command_names, command_name, **kw, &block) ⇒ Object
Uses the last command name to create a subcommand under the other named commands, with the block being the commands.
-
#on(*command_names, &block) ⇒ Object
Without a block, returns the Command instance for related subcommand (a nested subcommand if multiple command names are given).
-
#plugin(name) ⇒ Object
Load a plugin into the current processor.
-
#process(argv, *a, **kw) ⇒ Object
Process an argv array using a new instance of the class that is extended with Rodish::Processor.
Instance Attribute Details
#command ⇒ Object (readonly)
The root command for the processor.
9 10 11 |
# File 'lib/rodish/processor.rb', line 9 def command @command end |
Instance Method Details
#freeze ⇒ Object
Freeze the command and classes related to the processor when freezing the processor.
65 66 67 68 69 70 71 |
# File 'lib/rodish/processor.rb', line 65 def freeze command.freeze self::DSL.freeze self::DSL::Command.freeze self::DSL::OptionParser.freeze super end |
#is(*command_names, command_name, **kw, &block) ⇒ Object
Uses the last command name to create a subcommand under the other named commands, with the block being the commands
60 61 62 |
# File 'lib/rodish/processor.rb', line 60 def is(*command_names, command_name, **kw, &block) dsl(command_names).is(command_name, **kw, &block) end |
#on(*command_names, &block) ⇒ Object
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.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rodish/processor.rb', line 46 def on(*command_names, &block) if block if command_name = command_names.pop dsl(command_names).on(command_name, &block) else dsl(command_names).instance_exec(&block) end else dsl(command_names) end end |
#plugin(name) ⇒ Object
Load a plugin into the current processor.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rodish/processor.rb', line 12 def plugin(name, ...) mod = load_plugin(name) unless mod.respond_to?(:before_load) || mod.respond_to?(:after_load) _plugin_without_before_or_after_load_check(...) end mod.before_load(self, ...) if mod.respond_to?(:before_load) extend(mod::ProcessorMethods) if defined?(mod::ProcessorMethods) self::DSL.include(mod::DSLMethods) if defined?(mod::DSLMethods) self::DSL::Command.include(mod::CommandMethods) if defined?(mod::CommandMethods) self::DSL::OptionParser.include(mod::OptionParserMethods) if defined?(mod::OptionParserMethods) mod.after_load(self, ...) if mod.respond_to?(:after_load) nil end |
#process(argv, *a, **kw) ⇒ Object
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.
34 35 36 37 38 |
# File 'lib/rodish/processor.rb', line 34 def process(argv, *a, **kw) # Deliberately do not pass a block here, to reserve # block handling for future use. @command.process(new(*a, **kw), {}, argv) end |