Class: RailsSync::Adapter
- Inherits:
-
Object
- Object
- RailsSync::Adapter
- Extended by:
- ActiveRecord::ConnectionHandling
- Defined in:
- lib/rails_sync/adapter.rb
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(spec, options = {}) ⇒ Adapter
constructor
A new instance of Adapter.
- #retrieve_connection ⇒ Object
- #server_id ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(spec, options = {}) ⇒ Adapter
Returns a new instance of Adapter.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rails_sync/adapter.rb', line 7 def initialize(spec, = {}) @adapter_options = RailsSync..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 |
Instance Method Details
#connection ⇒ Object
37 38 39 |
# File 'lib/rails_sync/adapter.rb', line 37 def connection retrieve_connection end |
#retrieve_connection ⇒ Object
19 20 21 |
# File 'lib/rails_sync/adapter.rb', line 19 def retrieve_connection self.class.connection_handler.retrieve_connection(@adapter_options[:name]) end |
#server_id ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Object
41 42 43 |
# 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 |