Created
          January 19, 2010 03:52 
        
      - 
      
 - 
        
Save protocarl/280645 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | development: | |
| adapter: master_slave | |
| master: | |
| adapter: mysql | |
| database: master | |
| host: master_server | |
| slave: | |
| adapter: mysql | |
| database: slave | |
| host: localhost | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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