Skip to content

Instantly share code, notes, and snippets.

@protocarl
Created June 3, 2009 20:51
Show Gist options
  • Save protocarl/123241 to your computer and use it in GitHub Desktop.
Save protocarl/123241 to your computer and use it in GitHub Desktop.
require 'forwardable'
module DataMapper::Adapters
class MasterSlaveAdapter < AbstractAdapter
extend Forwardable
extend DataMapper::Migrations::SingletonMethods
def_delegators :@master, :storage_exists?, :field_exists?,
:upgrade_model_storage, :create_model_storage, :destroy_model_storage, :alter_model_storage,
:create_property_storage, :destroy_property_storage, :alter_property_storgae
attr_reader :name
def create(resources)
@master.create(resources)
end
def read(query)
@slave.read(query)
end
def update(attributes, collection)
@master.update(attributes, collection)
end
def delete(collection)
@master.delete(collection)
end
private
def initialize(name, options)
super(name, options)
assert_kind_of 'options', @options[:master], Hash
assert_kind_of 'options', @options[:slave], Hash
@master = ::DataMapper.setup("#{name}_master".intern, @options[:master])
@slave = ::DataMapper.setup("#{name}_slave".intern, @options[:slave] )
end
def method_missing(meth, *args, &block)
@slave.send(meth, *args, &block)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment