Class: Roby::Interface::V1::SubcommandClient
- Inherits:
-
Object
- Object
- Roby::Interface::V1::SubcommandClient
show all
- Defined in:
- lib/roby/interface/v1/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
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 19
def initialize(parent, name, description, commands)
@parent, @name, @description, @commands =
parent, name, description, commands
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 44
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/v1/subcommand_client.rb', line 17
def commands
@commands
end
|
#description ⇒ String
Returns the subcommand description.
15
16
17
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 15
def description
@description
end
|
13
14
15
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 13
def name
@name
end
|
Returns the parent shell / subcommand.
10
11
12
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 10
def parent
@parent
end
|
Instance Method Details
#async_call(path, m, *args, &block) ⇒ Object
32
33
34
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 32
def async_call(path, m, *args, &block)
parent.async_call([name] + path, m, *args, &block)
end
|
#call(path, m, *args) ⇒ Object
24
25
26
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 24
def call(path, m, *args)
parent.call([name] + path, m, *args)
end
|
#find_subcommand_by_name(m) ⇒ Object
36
37
38
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 36
def find_subcommand_by_name(m)
@commands[m.to_s]
end
|
#has_command?(m) ⇒ Boolean
40
41
42
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 40
def has_command?(m)
@commands.has_key?(m.to_s)
end
|
28
29
30
|
# File 'lib/roby/interface/v1/subcommand_client.rb', line 28
def path
parent.path + [name]
end
|