Class: Madeleine::Automatic::Prox
- Inherits:
-
Object
- Object
- Madeleine::Automatic::Prox
- Defined in:
- lib/madeleine/automatic.rb
Overview
A Prox object is generated and returned by Interceptor each time a system object is created.
Instance Attribute Summary collapse
-
#myid ⇒ Object
:nodoc:.
-
#sysid ⇒ Object
:nodoc:.
-
#thing ⇒ Object
:nodoc:.
Class Method Summary collapse
-
._load(str) ⇒ Object
Custom marshalling for Marshal - restore a Prox object.
Instance Method Summary collapse
-
#_dump(depth) ⇒ Object
marshal is always used for Command objects.
-
#initialize(thing) ⇒ Prox
constructor
A new instance of Prox.
-
#method_missing(symbol, *args, &block) ⇒ Object
outside the system.
Constructor Details
#initialize(thing) ⇒ Prox
Returns a new instance of Prox.
171 172 173 174 175 176 177 178 |
# File 'lib/madeleine/automatic.rb', line 171 def initialize(thing) if (thing) raise "App object created outside of app" unless Thread.current[:system] @sysid = Thread.current[:system].sysid @myid = Thread.current[:system].add(self) @thing = thing end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
outside the system.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/madeleine/automatic.rb', line 183 def method_missing(symbol, *args, &block) # print "Sending #{symbol} to #{@thing.to_s}, myid=#{@myid}, sysid=#{@sysid}\n" raise NoMethodError, "Undefined method" unless @thing.respond_to?(symbol) if (Thread.current[:system]) @thing.send(symbol, *args, &block) else raise "Cannot make command with block" if block_given? Thread.current[:system] = AutomaticSnapshotMadeleine.systems[@sysid] begin if (@thing.read_only_methods.include?(symbol)) result = Thread.current[:system].execute_query(Command.new(symbol, @myid, *args)) else result = Thread.current[:system].execute_command(Command.new(symbol, @myid, *args)) end ensure Thread.current[:system] = false end result end end |
Instance Attribute Details
#myid ⇒ Object
:nodoc:
169 170 171 |
# File 'lib/madeleine/automatic.rb', line 169 def myid @myid end |
#sysid ⇒ Object
:nodoc:
169 170 171 |
# File 'lib/madeleine/automatic.rb', line 169 def sysid @sysid end |
#thing ⇒ Object
:nodoc:
169 170 171 |
# File 'lib/madeleine/automatic.rb', line 169 def thing @thing end |
Class Method Details
._load(str) ⇒ Object
Custom marshalling for Marshal - restore a Prox object.
226 227 228 229 230 231 232 233 234 |
# File 'lib/madeleine/automatic.rb', line 226 def Prox._load(str) x = Prox.new(nil) a = str.unpack("A8A30a*") x.myid = a[0].to_i x.sysid = a[1] x = Thread.current[:system].restore(x) x.thing = Marshal.load(a[2]) if (a[2] > "") x end |
Instance Method Details
#_dump(depth) ⇒ Object
marshal is always used for Command objects
210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/madeleine/automatic.rb', line 210 def _dump(depth) if (Thread.current[:snapshot_memory]) if (Thread.current[:snapshot_memory][self]) [@myid.to_s, @sysid].pack("A8A30") else Thread.current[:snapshot_memory][self] = true [@myid.to_s, @sysid].pack("A8A30") + Marshal.dump(@thing, depth) end else [@myid.to_s, @sysid].pack("A8A30") # never marshal a prox object in a command, just ref end end |