Class: ReplicaConnect::Connection
- Inherits:
-
Object
- Object
- ReplicaConnect::Connection
- Defined in:
- lib/replica_connect.rb
Instance Method Summary collapse
- #clear_config ⇒ Object
- #connect ⇒ Object
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/replica_connect.rb', line 7 def initialize if File.exists?('rc_config.yml') file = YAML.load_file('rc_config.yml') configs = file['rc'] @username = configs['username'] @password = configs['password'] @db_name = configs['db'] @host = configs['host'] @adapter = configs['adapter'] else f = File.new('rc_config.yml', 'w+') f.puts "rc:" @username = get_from_user('username',f) @password = get_from_user('password',f) @db_name = get_from_user('db',f) @host = get_from_user('host',f) @adapter = get_from_user('adapter',f) f.close end end |
Instance Method Details
#clear_config ⇒ Object
37 38 39 |
# File 'lib/replica_connect.rb', line 37 def clear_config File.delete('rc_config.yml') unless !File.exists?('rc_config.yml') end |
#connect ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/replica_connect.rb', line 28 def connect ActiveRecord::Base.establish_connection( :adapter => @adapter, :host => @host, :database => @db_name, :username => @username, :password => @password).connection end |