class RailsSync::Adapter

Public Class Methods

new(spec, options = {}) click to toggle source
# File lib/rails_sync/adapter.rb, line 7
def initialize(spec, options = {})
  @adapter_options = RailsSync.options.fetch(spec, {})
  @adapter_options[:name] = spec

  begin
    self.connection
  rescue
    client = self.class.connection_handler.establish_connection(@adapter_options)
    puts "established connection: #{client}"
  end
end

Public Instance Methods

connection() click to toggle source
# File lib/rails_sync/adapter.rb, line 37
def connection
  retrieve_connection
end
retrieve_connection() click to toggle source
# File lib/rails_sync/adapter.rb, line 19
def retrieve_connection
  self.class.connection_handler.retrieve_connection(@adapter_options[:name])
end
server_id() click to toggle source
# File lib/rails_sync/adapter.rb, line 23
def server_id
  begin
    result = connection.query('select @@server_uuid')
  rescue
    result = connection.query('select @@server_id')
  end
  _id = result.to_a.flatten.first
  if _id.is_a?(Hash)
    _id.values.first
  else
    _id
  end
end
url() click to toggle source
# File lib/rails_sync/adapter.rb, line 41
def url
  @url ||= "mysql://#{@adapter_options[:username]}:#{@adapter_options[:password]}@#{@adapter_options[:host]}:#{@adapter_options[:port]}/#{@adapter_options[:database]}"
end