Class: Roby::Interface::CommandLibrary
- Extended by:
- MetaRuby::Attributes
- Defined in:
- lib/roby/interface/command_library.rb
Overview
Objects that hold a set of commands
Direct Known Subclasses
Defined Under Namespace
Classes: InterfaceCommands
Instance Attribute Summary collapse
-
#app ⇒ Roby::Application
readonly
The application.
-
#subcommands ⇒ Hash<String,CommandInterface>
readonly
The set of command subcommands attached to this command interface.
Class Method Summary collapse
-
.command(name, *info) ⇒ Object
Declares a command for this interface.
-
.subcommand(name, interface, *description) ⇒ Object
Adds another interface object a subcommand of this command interface.
Instance Method Summary collapse
-
#commands ⇒ Hash<String,InterfaceCommands>
The set of commands that exist on self and on its subcommands.
-
#each_subcommand {|name| ... } ⇒ Object
Enumerate the subcommands available on this interface.
-
#execution_engine ⇒ Roby::ExecutionEngine
The #plan‘s engine.
-
#initialize(app) ⇒ CommandLibrary
constructor
A new instance of CommandLibrary.
-
#plan ⇒ Roby::Plan
The #app‘s plan.
-
#subcommand(name, interface, description) ⇒ Object
Declare a subcommand on this interface.
Constructor Details
#initialize(app) ⇒ CommandLibrary
Returns a new instance of CommandLibrary.
49 50 51 52 53 54 55 56 |
# File 'lib/roby/interface/command_library.rb', line 49 def initialize(app) @app = app @subcommands = Hash.new self.class.each_subcommand do |name, (interface_model, description)| subcommand(name, interface_model.new(app), description) end end |
Instance Attribute Details
#app ⇒ Roby::Application (readonly)
Returns the application.
40 41 42 |
# File 'lib/roby/interface/command_library.rb', line 40 def app @app end |
#subcommands ⇒ Hash<String,CommandInterface> (readonly)
Returns the set of command subcommands attached to this command interface.
47 48 49 |
# File 'lib/roby/interface/command_library.rb', line 47 def subcommands @subcommands end |
Class Method Details
.command(name, *info) ⇒ Object
Declares a command for this interface
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/roby/interface/command_library.rb', line 11 def command(name, *info) arguments = if info.last.kind_of?(Hash) then info.pop else Hash.new end arguments = arguments.map_key do |name, _| name.to_sym end arguments = arguments.map_value do |name, description| CommandArgument.new(name.to_sym, Array(description)) end commands[name.to_sym] = Command.new(name.to_sym, info, arguments) end |
.subcommand(name, interface, *description) ⇒ Object
Adds another interface object a subcommand of this command interface
31 32 33 34 35 36 |
# File 'lib/roby/interface/command_library.rb', line 31 def subcommand(name, interface, *description) subcommands[name] = [interface, description] define_method name do subcommands[name].first end end |
Instance Method Details
#commands ⇒ Hash<String,InterfaceCommands>
The set of commands that exist on self and on its subcommands
83 84 85 86 87 88 89 |
# File 'lib/roby/interface/command_library.rb', line 83 def commands result = Hash['' => InterfaceCommands.new('', nil, self.class.commands)] each_subcommand do |name, interface, description| result[name] = InterfaceCommands.new(name, description, interface.commands) end result end |
#each_subcommand {|name| ... } ⇒ Object
Enumerate the subcommands available on this interface
69 70 71 72 73 74 |
# File 'lib/roby/interface/command_library.rb', line 69 def each_subcommand return enum_for(__method__) if !block_given? subcommands.each do |name, (interface, description)| yield(name, interface, description) end end |
#execution_engine ⇒ Roby::ExecutionEngine
Returns the #plan‘s engine.
44 |
# File 'lib/roby/interface/command_library.rb', line 44 def execution_engine; plan.execution_engine end |
#plan ⇒ Roby::Plan
Returns the #app‘s plan.
42 |
# File 'lib/roby/interface/command_library.rb', line 42 def plan; app.plan end |
#subcommand(name, interface, description) ⇒ Object
Declare a subcommand on this interface
Unless with subcommand, the interface must already be instanciated
62 63 64 |
# File 'lib/roby/interface/command_library.rb', line 62 def subcommand(name, interface, description) subcommands[name] = [interface, description] end |