class Syskit::Properties

A hash wrapper that gives access to properties in a more manageable way than using a hash or using {TaskContext#property} and {TaskContext#method_missing}

E.g.

task.properties.test = 10
task.properties.test # => 10

Public Class Methods

new(task, properties) click to toggle source
# File lib/syskit/properties.rb, line 12
def initialize(task, properties)
    @task = task
    @properties = properties
end

Public Instance Methods

[](name) click to toggle source

Returns a property by name

@return [Property,nil]

# File lib/syskit/properties.rb, line 35
def [](name)
    @properties[name.to_str]
end
__resolve_property(name) click to toggle source
# File lib/syskit/properties.rb, line 39
def __resolve_property(name)
    if p = @properties[name.to_str]
        return false, p
    elsif name.start_with?("raw_")
        non_raw_name = name[4..-1]
        if p = @properties[non_raw_name]
            return true, p
        else
            ::Kernel.raise ::Orocos::NotFound, "neither #{non_raw_name} nor #{name} are a property of #{@task}"
        end
    else
        ::Kernel.raise ::Orocos::NotFound, "#{name} is not a property of #{@task}"
    end
end
clear_values() click to toggle source

Clear all written values

# File lib/syskit/properties.rb, line 28
def clear_values
    @properties.each_value { |p| p.clear_value }
end
each(&block) click to toggle source

Enumerate the properties

# File lib/syskit/properties.rb, line 18
def each(&block)
    @properties.each_value(&block)
end
include?(name) click to toggle source

Whether there is a property with this name

# File lib/syskit/properties.rb, line 23
def include?(name)
    @properties.has_key?(name.to_str)
end
method_missing(m, *args) { |value| ... } click to toggle source
# File lib/syskit/properties.rb, line 54
def method_missing(m, *args)
    if m =~ /=$/
        raw, p = __resolve_property($`.to_s)
        if raw
            return p.raw_write(*args)
        else
            return p.write(*args)
        end
    else
        raw, p = __resolve_property(m.to_s)

        if raw
            value = p.raw_read(*args)
            if ::Kernel.block_given?
                return p.raw_write(yield(value))
            else
                return value
            end
        else
            value = p.read(*args)
            if ::Kernel.block_given?
                return p.write(yield(value))
            else
                return value
            end
        end
    end
end