Skip to content

Commit

Permalink
Proxy's now inherit from ActiveSupport::BasicObject
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed May 11, 2009
1 parent 4c391a2 commit 27da456
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
1 change: 0 additions & 1 deletion Rakefile
Expand Up @@ -24,7 +24,6 @@ require 'spec/rake/spectask'
s.has_rdoc = true s.has_rdoc = true
s.rubyforge_project = "distribunaut" s.rubyforge_project = "distribunaut"
s.add_dependency('configatron') s.add_dependency('configatron')
s.add_dependency('cachetastic')
s.add_dependency('addressable') s.add_dependency('addressable')
s.add_dependency('daemons') s.add_dependency('daemons')
# s.test_files = FileList['spec/**/*'] # s.test_files = FileList['spec/**/*']
Expand Down
19 changes: 7 additions & 12 deletions lib/distribunaut/distributable.rb
Expand Up @@ -22,25 +22,20 @@ def self.included(base) # :nodoc:
end end
c_name = base.name.gsub('::', '_') c_name = base.name.gsub('::', '_')
eval %{ eval %{
class ::Distribunaut::Distributed::#{c_name}Proxy class ::Distribunaut::Distributed::#{c_name}Proxy < ActiveSupport::BasicObject
include Singleton
include DRbUndumped
def method_missing(sym, *args) def method_missing(sym, *args)
#{base}.send(sym, *args) #{base}.send(sym, *args)
end end
def inspect
#{base}.inspect
end
def to_s
#{base}.to_s
end
end end
} }
obj = "Distribunaut::Distributed::#{c_name}Proxy".constantize.instance const = "Distribunaut::Distributed::#{c_name}Proxy".constantize
const.class_eval do
include Singleton
include ::DRbUndumped
end
obj = const.instance
raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil? raise Distribunaut::Distributed::Errors::ApplicationNameUndefined.new if configatron.distribunaut.app_name.nil?
Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym, Distribunaut::Utils::Rinda.register_or_renew(:space => "#{base}".to_sym,
:object => obj, :object => obj,
Expand Down
31 changes: 27 additions & 4 deletions spec/distribunaut/distributable_spec.rb
Expand Up @@ -27,8 +27,6 @@ class Dylan
include Distribunaut::Distributable include Distribunaut::Distributable
end end
Distribunaut::Distributed.should be_const_defined('DylanProxy') Distribunaut::Distributed.should be_const_defined('DylanProxy')
Distribunaut::Distributed::DylanProxy.instance.should be_kind_of(::Singleton)
Distribunaut::Distributed::DylanProxy.instance.should be_kind_of(::DRbUndumped)
end end


it 'should create proxy objects for modularize classes' do it 'should create proxy objects for modularize classes' do
Expand All @@ -39,8 +37,33 @@ class Dylan
end end
end end
Distribunaut::Distributed.should be_const_defined('Bob_DylanProxy') Distribunaut::Distributed.should be_const_defined('Bob_DylanProxy')
Distribunaut::Distributed::Bob_DylanProxy.instance.should be_kind_of(::Singleton) end
Distribunaut::Distributed::Bob_DylanProxy.instance.should be_kind_of(::DRbUndumped)
it 'should pass calls from the proxy to the base object' do
class Axl
include Distribunaut::Distributable

def inspect
"Sweet Child O'Mine"
end

def yell
'YEAH!!!!'
end

def self.find
[self.new, self.new]
end

end

axl_proxy = Distribunaut::Distributed::Axl.new
axl_proxy.inspect.should == "Sweet Child O'Mine"
axl_proxy.yell.should == 'YEAH!!!!'

axls = Distribunaut::Distributed::Axl.find
axls.should be_kind_of(Array)
axls.size.should == 2
end end


end end
2 changes: 1 addition & 1 deletion spec/distribunaut/distributed/distributed_spec.rb
Expand Up @@ -15,7 +15,7 @@ def processor
"Intel" "Intel"
end end
end end
Distribunaut::Distributed::Computer.should be_kind_of(Distribunaut::Distributed::ComputerProxy) Distribunaut::Distributed::Computer.should be ::Computer
comp = Distribunaut::Distributed::Computer.new comp = Distribunaut::Distributed::Computer.new
comp.processor.should == "Intel" comp.processor.should == "Intel"
end end
Expand Down

0 comments on commit 27da456

Please sign in to comment.