Module: Roby::Models::Arguments

Extended by:
MetaRuby::Attributes
Included in:
Task, TaskServiceModel
Defined in:
lib/roby/models/arguments.rb

Overview

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

Defined Under Namespace

Classes: Argument

Constant Summary collapse

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

Object.new

Instance Method Summary collapse

Instance Method Details

#argument(argument_name, options) ⇒ Object

Examples:

getting an argument at runtime from another object

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

getting an argument at runtime from the global configuration

argument :target_point, default: from_conf.target_position

defining ‘nil’ as a default value

argument :main_direction, default: nil

defining an example value

argument :maximum_current, example: 42

Parameters:

  • argument_name (String)

    the name of the new argument

  • options (Hash)
  • 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)

  • doc

    documentation string for the argument. If left to nil, the method will attempt to extract the argument’s documentation block.

  • example

    set an example to be used when doesnt have a default value for unit tests.



30
# File 'lib/roby/models/arguments.rb', line 30

inherited_attribute("argument", "__arguments", map: true) { {} }

#argumentsArray<String>

Returns the list of arguments required by this task model.

Returns:

  • (Array<String>)

    the list of arguments required by this task model



33
34
35
# File 'lib/roby/models/arguments.rb', line 33

def arguments
    each_argument.map { |name, _| name }
end

#default_argument(argname) ⇒ (Boolean,Object)

Access an argument’s default value

Parameters:

  • argname (String)

    the argument name

Returns:

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



91
92
93
94
95
# File 'lib/roby/models/arguments.rb', line 91

def default_argument(argname)
    if (arg = find_argument(argname)) && arg.has_default?
        [true, arg.default]
    end
end

#fullfills?(models) ⇒ Boolean

Checks if this model fullfills everything in models

Returns:

  • (Boolean)


110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/roby/models/arguments.rb', line 110

def fullfills?(models)
    unless models.respond_to?(:each)
        models = [models]
    end

    for tag in models
        unless has_ancestor?(tag)
            return false
        end
    end
    true
end

#meaningful_arguments(arguments) ⇒ Object

The part of arguments that is meaningful for this task model



98
99
100
101
102
103
104
105
106
107
# File 'lib/roby/models/arguments.rb', line 98

def meaningful_arguments(arguments)
    self_arguments = self.arguments
    result = {}
    arguments.each_assigned_argument do |key, value|
        if self_arguments.include?(key)
            result[key] = value
        end
    end
    result
end