Class: Roby::DRoby::V5::DRobyConstant

Inherits:
Object
  • Object
show all
Defined in:
lib/roby/droby/v5/droby_constant.rb

Overview

Dumps a constant by using its name. On reload, #proxy searches for a constant with the same name, and raises ArgumentError if none exists.

Examples:

dump instances of a class that are registered as constants

class Klass
  include DRobyConstant::Dump
end
# Obj can pass through droby
Obj = Klass.new

dump classes. You usually would prefer using DRobyModel

# Klass can pass through droby
class Klass
  extend DRobyConstant::Dump
end

Defined Under Namespace

Modules: Dump

Constant Summary collapse

@@valid_constants =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, remote_siblings = {}) ⇒ DRobyConstant

Returns a new instance of DRobyConstant.



83
84
85
86
87
# File 'lib/roby/droby/v5/droby_constant.rb', line 83

def initialize(name, remote_siblings = {})
    @name = name
    @remote_siblings = remote_siblings
    @constant_renaming = []
end

Instance Attribute Details

#nameObject (readonly)

The constant name



81
82
83
# File 'lib/roby/droby/v5/droby_constant.rb', line 81

def name
  @name
end

#remote_siblingsObject (readonly)

Returns the value of attribute remote_siblings.



78
79
80
# File 'lib/roby/droby/v5/droby_constant.rb', line 78

def remote_siblings
  @remote_siblings
end

Class Method Details

.clear_cacheObject



22
23
24
# File 'lib/roby/droby/v5/droby_constant.rb', line 22

def self.clear_cache
    @@valid_constants.clear
end

.find_constant_renaming(name) ⇒ Object



117
118
119
120
121
122
# File 'lib/roby/droby/v5/droby_constant.rb', line 117

def self.find_constant_renaming(name)
    @constant_renaming.each do |from, to|
        return name.gsub(from, to) if from === name
    end
    nil
end

.map_constant_name(from, to) ⇒ Object



111
112
113
114
115
# File 'lib/roby/droby/v5/droby_constant.rb', line 111

def self.map_constant_name(from, to)
    item = [from, to]
    @constant_renaming << item
    Roby.disposable { @constant_renaming.delete(item) }
end

.valid_constantsObject



27
28
29
# File 'lib/roby/droby/v5/droby_constant.rb', line 27

def self.valid_constants
    @@valid_constants
end

Instance Method Details

#find_constant_renaming(name) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/roby/droby/v5/droby_constant.rb', line 101

def find_constant_renaming(name)
    (@constant_renaming ||= []).each do |from, to|
        return name.gsub(from, to) if from === name
    end

    self.class.find_constant_renaming(name)
end

#map_constant_name(from, to) ⇒ Object



95
96
97
98
99
# File 'lib/roby/droby/v5/droby_constant.rb', line 95

def map_constant_name(from, to)
    item = [from, to]
    (@constant_renaming ||= []) << item
    Roby.disposable { @constant_renaming.delete(item) }
end

#proxy(peer) ⇒ Object

Returns the local object which can be referenced by this name, or raises ArgumentError.



91
92
93
# File 'lib/roby/droby/v5/droby_constant.rb', line 91

def proxy(peer)
    constant(find_constant_renaming(name) || name)
end

#to_sObject



31
32
33
# File 'lib/roby/droby/v5/droby_constant.rb', line 31

def to_s
    "#<dRoby:Constant #{name}>"
end