Class: Roby::DRoby::V5::DRobyConstant
- 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.
Defined Under Namespace
Modules: Dump
Constant Summary collapse
- @@valid_constants =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The constant name.
-
#remote_siblings ⇒ Object
readonly
Returns the value of attribute remote_siblings.
Class Method Summary collapse
- .clear_cache ⇒ Object
- .find_constant_renaming(name) ⇒ Object
- .map_constant_name(from, to) ⇒ Object
- .valid_constants ⇒ Object
Instance Method Summary collapse
- #find_constant_renaming(name) ⇒ Object
-
#initialize(name, remote_siblings = {}) ⇒ DRobyConstant
constructor
A new instance of DRobyConstant.
- #map_constant_name(from, to) ⇒ Object
-
#proxy(peer) ⇒ Object
Returns the local object which can be referenced by this name, or raises ArgumentError.
- #to_s ⇒ Object
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
#name ⇒ Object (readonly)
The constant name
81 82 83 |
# File 'lib/roby/droby/v5/droby_constant.rb', line 81 def name @name end |
#remote_siblings ⇒ Object (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_cache ⇒ Object
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_constants ⇒ Object
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_s ⇒ Object
31 32 33 |
# File 'lib/roby/droby/v5/droby_constant.rb', line 31 def to_s "#<dRoby:Constant #{name}>" end |