Class: ClassRoom::Client::ProxyObject

Inherits:
Object
  • Object
show all
Defined in:
lib/classroom.rb

Overview

ProxyObject acts as a local proxy for ClassRoom clients and handles passing through requests to run class methods and initializations

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ProxyObject

Create an instance of the remote class



218
219
220
# File 'lib/classroom.rb', line 218

def initialize(*args)
  @drbed_object = drb.send(:new_instance_of, self.class.to_s.to_sym, *args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Return the ‘real’ class name def class; @class_name; end



232
233
234
# File 'lib/classroom.rb', line 232

def method_missing(method, *args)
  @drbed_object.send(method, *args)
end

Class Method Details

.class_nameObject



212
# File 'lib/classroom.rb', line 212

def self.class_name; @@class_name[self.to_s.to_sym]; end

.class_name=(d) ⇒ Object



213
# File 'lib/classroom.rb', line 213

def self.class_name=(d); (@@class_name ||= {})[self.to_s.to_sym] = d; end

.drbObject

Set up a weird /true/ class variable system (that is, class variable == class variable, not weird hierarchy variable-foo as is Ruby’s wont)



210
# File 'lib/classroom.rb', line 210

def self.drb; @@drb[self.to_s.to_sym]; end

.drb=(d) ⇒ Object



211
# File 'lib/classroom.rb', line 211

def self.drb=(d); (@@drb ||= {})[self.to_s.to_sym] = d; end

.method_missing(method, *args) ⇒ Object

If we’re getting methods called on the proxy, they must be for the remote class rather than a method, so ask the ClassRoom server to run the class_method on the supplied object



225
226
227
# File 'lib/classroom.rb', line 225

def self.method_missing(method, *args)
  drb.send(:class_method, class_name, method, *args)
end

Instance Method Details

#class_nameObject



215
# File 'lib/classroom.rb', line 215

def class_name; @@class_name[self.class.to_s.to_sym]; end

#drbObject



214
# File 'lib/classroom.rb', line 214

def drb; @@drb[self.class.to_s.to_sym]; end