module Roby::DRoby::V5::DRobyConstant::Dump

Generic implementation of the constant-dumping method. This is to be included in all kind of classes which should be dumped by their constant name (for intance Relations::Graph).

Public Instance Methods

droby_dump(peer) click to toggle source

Returns a DRobyConstant object which references self. It checks that self can actually be referenced locally by calling constant(name), or raises ArgumentError if it is not the case.

# File lib/roby/droby/v5/droby_constant.rb, line 39
def droby_dump(peer)
    if constant = DRobyConstant.valid_constants[self]
        return constant
    elsif !name
        raise ConstantResolutionFailed, "#{self}#name returned nil"
    end

    name = "::#{self.name}"

    begin
        local_constant = constant(name)
    rescue Exception => e
        Roby.warn "could not resolve constant name for #{self}"
        Roby.log_exception(e, Roby, :warn)
        raise ConstantResolutionFailed, "cannot resolve constant name for #{self}"
    end

    if (local_constant == self)
        DRobyConstant.valid_constants[self] = DRobyConstant.new(name, peer.known_siblings_for(self))
    else
        raise MismatchingLocalConstant, "got DRobyConstant whose name '#{name}' resolves to #{local_constant}(#{local_constant.class}), not itself (#{self})"
    end
end