Class: Roby::Interface::V2::SubcommandClient

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/interface/v2/subcommand_client.rb

Overview

Representation of a subcommand on Interface on the shell side

Direct Known Subclasses

ShellSubcommand

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commandsHash<String,Command> (readonly)

Returns the set of commands on this subcommand.

Returns:

  • (Hash<String,Command>)

    the set of commands on this subcommand



17
18
19
# File 'lib/roby/interface/v2/subcommand_client.rb', line 17

def commands
  @commands
end

#descriptionString (readonly)

Returns the subcommand description.

Returns:

  • (String)

    the subcommand description



15
16
17
# File 'lib/roby/interface/v2/subcommand_client.rb', line 15

def description
  @description
end

#nameObject (readonly)

Returns:

  • [

  • (String)

    the subcommand name



13
14
15
# File 'lib/roby/interface/v2/subcommand_client.rb', line 13

def name
  @name
end

#parentShellClient, ShellSubcommand (readonly)

Returns the parent shell / subcommand.

Returns:



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

Returns:

  • (Boolean)


42
43
44
# File 'lib/roby/interface/v2/subcommand_client.rb', line 42

def has_command?(m)
    @commands.key?(m.to_s)
end

#pathObject



30
31
32
# File 'lib/roby/interface/v2/subcommand_client.rb', line 30

def path
    parent.path + [name]
end