Skip to content

Instantly share code, notes, and snippets.

@protocarl
Created January 19, 2010 03:52
Show Gist options
  • Save protocarl/280645 to your computer and use it in GitHub Desktop.
Save protocarl/280645 to your computer and use it in GitHub Desktop.
development:
adapter: master_slave
master:
adapter: mysql
database: master
host: master_server
slave:
adapter: mysql
database: slave
host: localhost
require 'forwardable'
module DataMapper::Adapters
class MasterSlaveAdapter < AbstractAdapter
extend Forwardable
attr_reader :name
def_delegators :@master, :create, :update, :delete
def_delegators :@slave, :read
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