Class: Roby::Interface::V1::SubcommandClient

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/interface/v1/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
# 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

#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/v1/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/v1/subcommand_client.rb', line 15

def description
  @description
end

#nameObject (readonly)

Returns:

  • [

  • (String)

    the subcommand name



13
14
15
# File 'lib/roby/interface/v1/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/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

Returns:

  • (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

#pathObject



28
29
30
# File 'lib/roby/interface/v1/subcommand_client.rb', line 28

def path
    parent.path + [name]
end