module Roby::Coordination::Models::Arguments

Constants

Argument

Public Instance Methods

argument(name, options = Hash.new) click to toggle source

Define a new argument for this coordination model

Arguments are made available within the coordination model as Variable objects

@param [String,Symbol] name the argument name @param [Hash] options @option options :default a default value for this argument. Note

that 'nil' is considered as a proper default value.

@return [Argument] the new argument object

# File lib/roby/coordination/models/arguments.rb, line 23
def argument(name, options = Hash.new)
    options = Kernel.validate_options options, :default
    arguments[name.to_sym] = Argument.new(name.to_sym, !options.has_key?(:default), options[:default])
end
validate_arguments(arguments) click to toggle source

Validates that the provided argument hash is valid for this particular coordination model

@raise ArgumentError if some given arguments are not known to this

model, or if some required arguments are not set
# File lib/roby/coordination/models/arguments.rb, line 33
def validate_arguments(arguments)
    arguments = Kernel.normalize_options arguments
    arguments.keys.each do |arg_name|
        if !find_argument(arg_name)
            raise ArgumentError, "#{arg_name} is not an argument on #{self}"
        end
    end
    each_argument do |_, arg|
        if !arguments.has_key?(arg.name)
            if arg.required
                raise ArgumentError, "#{arg.name} is required by #{self}, but is not provided (given arguments: #{arguments})"
            end
            arguments[arg.name] = arg.default
        end
    end
    arguments
end