Module: Distribunaut::Distributable
- Defined in:
- lib/distribunaut/distributable.rb
Overview
Include this module into any class it will instantly register that class with the distribunaut_ring_server. The class will be registered with the name of the class and the distribunaut.distributed_app_name configured in your config/configatron/*.rb file. If the distribunaut.distributed_app_name configuration parameter is nil it will raise an Distribunaut::Distributed::Errors::ApplicationNameUndefined exception.
Example:
class User
include Distribunaut::Distributable
def name
"mark"
end
end
Distribunaut::Distributed::User.new.name # => "mark"
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
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 52 53 54 |
# File 'lib/distribunaut/distributable.rb', line 19 def self.included(base) # :nodoc: raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil? base.class_eval do include ::DRbUndumped end c_name = base.name.gsub('::', '_') eval %{ class ::Distribunaut::Distributed::#{c_name}Proxy include Singleton include DRbUndumped def method_missing(sym, *args) #{base}.send(sym, *args) end undef :id if method_defined?(:id) undef :inspect if method_defined?(:inspect) undef :to_s if method_defined?(:to_s) def borrow(&block) Distribunaut::Utils::Rinda.borrow(:space => :#{base}, :object => self, :description => "#{base} Service", :app_name => configatron.distribunaut.app_name.to_sym) do |tuple| yield tuple.object end end end } obj = "Distribunaut::Distributed::#{c_name}Proxy".constantize.instance Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym, :object => obj, :description => "#{base} Service", :app_name => configatron.distribunaut.app_name.to_sym) end |