Sha256: b728b55b1174e4bc040a5a3004c43f58164c09d881b5006dbd8531d791c9fb14

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module MysqlReplicationHelper
  class Agent
    autoload(:Master, 'mysql_replication_helper/agent/master')
    autoload(:Slave, 'mysql_replication_helper/agent/slave')

    DEFAULT_OPTIONS = {
      :host => 'localhost',
      :user => 'root',
      :master_socket => '/local/db/mysql.sock',
      :slave_socket => '/ebs/db/mysql.sock'
    }
    
    def initialize(options)
      @options = with_default_options(options)
    end
    
    def connection
      @connection ||=
        Mysql.real_connect(
          @options[:host],
          user_name,
          @options[:password],
          @options[:db],
          @options[:port],
          socket_name
        )
    end
    
    def user_name
      @options[:user]
    end
    
    def socket_name
      @options[:socket]
    end
    
    def with_default_options(options)
      DEFAULT_OPTIONS.merge(options)
    end
    
    def execute(statement)
      STDERR.puts(statement)
      connection.real_query(statement)
    end
    
    def query(statement)
      STDERR.puts(statement)
      connection.query(statement)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
theworkinggroup-mysql-replication-helper-0.2.0 lib/mysql_replication_helper/agent.rb
mysql-replication-helper-0.2.1 lib/mysql_replication_helper/agent.rb