module Roby::Models::Arguments

Support for argument handling in the relevant models (task services and tasks)

Constants

Argument

Representation of one argument

NO_DEFAULT_ARGUMENT

The null object used in {#argument} to signify that there are no default arguments

nil cannot be used as 'nil' is a valid default as well

Public Instance Methods

argument(name, default: NO_DEFAULT_ARGUMENT, doc: nil) click to toggle source

@overload argument(argument_name, options)

@param [String] argument_name the name of the new argument
@param [Hash] options
@param default the default value for this argument. It
  can either be a plain value (e.g. a number) or one of the
  delayed arguments (see examples below)
@param doc documentation string for the argument. If left
  to nil, the method will attempt to extract the argument's
  documentation block.

@example getting an argument at runtime from another object

argument :target_point, default: from(:planned_task).target_point

@example getting an argument at runtime from the global configuration

argument :target_point, default: from_conf.target_position

@example defining 'nil' as a default value

argument :main_direction, default: nil
# File lib/roby/models/arguments.rb, line 57
def argument(name, default: NO_DEFAULT_ARGUMENT, doc: nil)
    name = name.to_sym
    if !TaskArguments.delayed_argument?(default)
        default = DefaultArgument.new(default)
    end
    doc ||= MetaRuby::DSLs.parse_documentation_block /\.rb$/, 'argument'
    __arguments[name] = Argument.new(name, default, doc)

    if name =~ /^\w+$/ && !method_defined?(name)
        define_method(name) { arguments[name] }
        define_method("#{name}=") { |value| arguments[name] = value }
    end
end
arguments() click to toggle source

@return [Array<String>] the list of arguments required by this task model

# File lib/roby/models/arguments.rb, line 27
def arguments
    each_argument.map { |name, _| name }
end
default_argument(argname) click to toggle source

Access an argument's default value

@param [String] argname the argument name @return [(Boolean,Object)] the first returned value determines

whether there is a default defined for the requested argument and
the second is that value. Note that the default value can be nil.
# File lib/roby/models/arguments.rb, line 77
def default_argument(argname)
    if (arg = find_argument(argname)) && arg.has_default?
        return true, arg.default
    end
end
fullfills?(models) click to toggle source

Checks if this model fullfills everything in models

# File lib/roby/models/arguments.rb, line 96
def fullfills?(models)
    if !models.respond_to?(:each)
        models = [models]
    end

    for tag in models
        if !has_ancestor?(tag)
            return false
        end
    end
    true
end
meaningful_arguments(arguments) click to toggle source

The part of arguments that is meaningful for this task model

# File lib/roby/models/arguments.rb, line 84
def meaningful_arguments(arguments)
    self_arguments = self.arguments
    result = Hash.new
    arguments.each_assigned_argument do |key, value|
        if self_arguments.include?(key)
            result[key] = value
        end
    end
    result
end