Module: Roby::Coordination::Models::Arguments

Extended by:
MetaRuby::Attributes
Included in:
Base, FaultResponseTable
Defined in:
lib/roby/coordination/models/arguments.rb

Defined Under Namespace

Classes: Argument

Instance Method Summary collapse

Instance Method Details

#argument(name, options = {}) ⇒ Argument

Define a new argument for this coordination model

Arguments are made available within the coordination model as Variable objects

Parameters:

  • name (String, Symbol)

    the argument name

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :default (Object)

    a default value for this argument. Note that ‘nil’ is considered as a proper default value.

Returns:

  • (Argument)

    the new argument object



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

inherited_attribute(:argument, :arguments, map: true) { {} }

#validate_arguments(arguments) ⇒ Object

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

Raises:

  • ArgumentError if some given arguments are not known to this model, or if some required arguments are not set



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/roby/coordination/models/arguments.rb', line 35

def validate_arguments(arguments)
    arguments = Kernel.normalize_options arguments
    arguments.each_key do |arg_name|
        unless find_argument(arg_name)
            raise ArgumentError,
                  "#{arg_name} is not an argument on #{self}"
        end
    end

    each_argument do |_, arg|
        next 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
    arguments
end