Module: Mack::Distributable

Defined in:
lib/mack-distributed/distributable.rb

Overview

Include this module into any class it will instantly register that class with the mack_ring_server. The class will be registered with the name of the class and the mack.distributed_app_name configured in your config/configatron/*.rb file. If the mack.distributed_app_name configuration parameter is nil it will raise an Mack::Distributed::Errors::ApplicationNameUndefined exception.

Example:

class User
  include Mack::Distributable
  def name
    "mark"
  end
end

Mack::Distributed::User.new.name # => "mark"

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mack-distributed/distributable.rb', line 19

def self.included(base) # :nodoc:
  if configatron.mack.distributed.share_objects
    base.class_eval do
      include ::DRbUndumped
    end
    eval %{
      class ::Mack::Distributed::#{base}Proxy
        include Singleton
        include DRbUndumped

        def method_missing(sym, *args)
          #{base}.send(sym, *args)
        end
        
        def inspect
          #{base}.inspect
        end
        
        def to_s
          #{base}.to_s
        end
      
        # def respond_to?(sym)
        #   #{base}.respond_to?(sym)
        # end
      end
    }
    raise Mack::Distributed::Errors::ApplicationNameUndefined.new if configatron.mack.distributed.app_name.nil?
    Mack::Distributed::Utils::Rinda.register_or_renew(:space => configatron.mack.distributed.app_name.to_sym, 
                                                      :klass_def => "#{base}".to_sym, 
                                                      :object => "Mack::Distributed::#{base}Proxy".constantize.instance)
  end
end