Skip to content

Instantly share code, notes, and snippets.

@hryk
Forked from protocarl/database.yml
Created May 30, 2010 13:31
Show Gist options
  • Save hryk/419021 to your computer and use it in GitHub Desktop.
Save hryk/419021 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