Class: MysqlReplicationHelper::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql_replication_helper/agent.rb,
lib/mysql_replication_helper/agent/master.rb

Direct Known Subclasses

Master

Defined Under Namespace

Classes: Master

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :host => 'localhost',
  :user => 'root',
  :master_socket => '/local/db/mysql.sock',
  :slave_socket => '/ebs/db/mysql.sock'
}

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Agent

Returns a new instance of Agent.



13
14
15
# File 'lib/mysql_replication_helper/agent.rb', line 13

def initialize(options)
  @options = with_default_options(options)
end

Instance Method Details

#connectionObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mysql_replication_helper/agent.rb', line 17

def connection
  @connection ||=
    Mysql.real_connect(
      @options[:host],
      user_name,
      @options[:password],
      @options[:db],
      @options[:port],
      socket_name
    )
end

#execute(statement) ⇒ Object



41
42
43
44
# File 'lib/mysql_replication_helper/agent.rb', line 41

def execute(statement)
  STDERR.puts(statement)
  connection.real_query(statement)
end

#query(statement) ⇒ Object



46
47
48
49
# File 'lib/mysql_replication_helper/agent.rb', line 46

def query(statement)
  STDERR.puts(statement)
  connection.query(statement)
end

#socket_nameObject



33
34
35
# File 'lib/mysql_replication_helper/agent.rb', line 33

def socket_name
  @options[:socket]
end

#user_nameObject



29
30
31
# File 'lib/mysql_replication_helper/agent.rb', line 29

def user_name
  @options[:user]
end

#with_default_options(options) ⇒ Object



37
38
39
# File 'lib/mysql_replication_helper/agent.rb', line 37

def with_default_options(options)
  DEFAULT_OPTIONS.merge(options)
end