Class: Roby::Interface::V2::SubcommandClient
- Inherits:
-
Object
- Object
- Roby::Interface::V2::SubcommandClient
show all
- Defined in:
- lib/roby/interface/v2/subcommand_client.rb
Overview
Representation of a subcommand on Interface on the shell side
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#async_call(path, m, *args, &block) ⇒ Object
-
#call(path, m, *args) ⇒ Object
-
#find_subcommand_by_name(m) ⇒ Object
-
#has_command?(m) ⇒ Boolean
-
#initialize(parent, name, description, commands) ⇒ SubcommandClient
constructor
A new instance of SubcommandClient.
-
#method_missing(m, *args, &block) ⇒ Object
-
#path ⇒ Object
Constructor Details
#initialize(parent, name, description, commands) ⇒ SubcommandClient
Returns a new instance of SubcommandClient.
19
20
21
22
23
24
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 19
def initialize(parent, name, description, commands)
@parent = parent
@name = name
@description = description
@commands = commands
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 46
def method_missing(m, *args, &block)
if (sub = find_subcommand_by_name(m))
SubcommandClient.new(self, m, sub.description, sub.commands)
elsif (match = /^async_(.*)$/.match(m.to_s))
async_call([], match[1].to_sym, *args, &block)
else
call([], m, *args)
end
end
|
Instance Attribute Details
#commands ⇒ Hash<String,Command>
Returns the set of commands on this subcommand.
17
18
19
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 17
def commands
@commands
end
|
#description ⇒ String
Returns the subcommand description.
15
16
17
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 15
def description
@description
end
|
13
14
15
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 13
def name
@name
end
|
Returns the parent shell / subcommand.
10
11
12
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 10
def parent
@parent
end
|
Instance Method Details
#async_call(path, m, *args, &block) ⇒ Object
34
35
36
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 34
def async_call(path, m, *args, &block)
parent.async_call([name] + path, m, *args, &block)
end
|
#call(path, m, *args) ⇒ Object
26
27
28
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 26
def call(path, m, *args)
parent.call([name] + path, m, *args)
end
|
#find_subcommand_by_name(m) ⇒ Object
38
39
40
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 38
def find_subcommand_by_name(m)
@commands[m.to_s]
end
|
#has_command?(m) ⇒ Boolean
42
43
44
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 42
def has_command?(m)
@commands.key?(m.to_s)
end
|
30
31
32
|
# File 'lib/roby/interface/v2/subcommand_client.rb', line 30
def path
parent.path + [name]
end
|