Module: Roby::Transaction::Proxying
- Defined in:
- lib/roby/transaction/proxying.rb
Defined Under Namespace
Modules: Cache
Constant Summary collapse
- @@proxy_for =
{}
Instance Attribute Summary collapse
-
#__getobj__ ⇒ Object
readonly
Returns the value of attribute __getobj__.
Class Method Summary collapse
- .create_forwarder_module(methods) ⇒ Object
- .define_proxying_module(proxying_module, mod) ⇒ Object
-
.forwarder_module_for(klass) ⇒ Object
Returns a module that, when used to extend an object, will forward all the calls to the object’s @__getobj__.
-
.proxying_module_for(klass) ⇒ Object
Returns the proxying module for
object
.
Instance Method Summary collapse
-
#has_sibling?(peer) ⇒ Boolean
True if
peer
has a representation of this object. - #pretty_print(pp) ⇒ Object
- #proxying? ⇒ Boolean
- #setup_proxy(object, plan) ⇒ Object
- #to_s ⇒ Object
- #transaction_proxy? ⇒ Boolean
Instance Attribute Details
#__getobj__ ⇒ Object (readonly)
Returns the value of attribute __getobj__.
95 96 97 |
# File 'lib/roby/transaction/proxying.rb', line 95 def __getobj__ @__getobj__ end |
Class Method Details
.create_forwarder_module(methods) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/roby/transaction/proxying.rb', line 70 def self.create_forwarder_module(methods) Module.new do attr_accessor :__getobj__ def transaction_proxy? true end methods.each do |name| next if name =~ /^__.*__$/ next if name == :object_id define_method(name) do |*args, &block| __getobj__.send(name, *args, &block) end end end end |
.define_proxying_module(proxying_module, mod) ⇒ Object
45 46 47 48 |
# File 'lib/roby/transaction/proxying.rb', line 45 def self.(, mod) @@proxy_for[mod] = nil end |
.forwarder_module_for(klass) ⇒ Object
Returns a module that, when used to extend an object, will forward all the calls to the object’s @__getobj__
90 91 92 93 |
# File 'lib/roby/transaction/proxying.rb', line 90 def self.forwarder_module_for(klass) klass.transaction_forwarder_module ||= create_forwarder_module(klass.instance_methods(true)) end |
.proxying_module_for(klass) ⇒ Object
Returns the proxying module for object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/roby/transaction/proxying.rb', line 51 def self.(klass) if = klass.transaction_proxy_module return end modules = klass.ancestors.map do |ancestor| if mod_proxy = @@proxy_for[ancestor] mod_proxy end end.compact modules << Transaction:: = Module.new modules.reverse.each do |mod| .include mod end klass.transaction_proxy_module = end |
Instance Method Details
#has_sibling?(peer) ⇒ Boolean
True if peer
has a representation of this object
In the case of transaction proxies, we know they have siblings if the transaction is present on the other peer.
126 127 128 |
# File 'lib/roby/transaction/proxying.rb', line 126 def has_sibling?(peer) plan.has_sibling?(peer) end |
#pretty_print(pp) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/roby/transaction/proxying.rb', line 107 def pretty_print(pp) if plan plan. do pp.text "TProxy:" __getobj__.pretty_print(pp) end else super end end |
#proxying? ⇒ Boolean
118 119 120 |
# File 'lib/roby/transaction/proxying.rb', line 118 def plan&. end |
#setup_proxy(object, plan) ⇒ Object
101 102 103 |
# File 'lib/roby/transaction/proxying.rb', line 101 def setup_proxy(object, plan) @__getobj__ = object end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/roby/transaction/proxying.rb', line 41 def to_s "tProxy(#{__getobj__})" end |
#transaction_proxy? ⇒ Boolean
97 98 99 |
# File 'lib/roby/transaction/proxying.rb', line 97 def transaction_proxy? true end |