Class: Arrival::ConnectionDetails
- Inherits:
-
Object
- Object
- Arrival::ConnectionDetails
- Defined in:
- lib/arrival/connection_details.rb
Overview
Holds the parameters of the DB connection and formats them to string
Constant Summary collapse
- DEFAULT_PORT =
3306
Instance Method Summary collapse
-
#database ⇒ String
TODO: Doesn’t the abstract adapter already handle this somehow? Returns the database name.
-
#host_argument ⇒ String
Returns the host fragment of the details string, adds ssl options if needed.
-
#initialize(connection_data) ⇒ ConnectionDetails
constructor
Constructor.
-
#password_argument ⇒ String
Returns the password fragment of the details string if a password is passed.
-
#to_s ⇒ String
Returns the details formatted as an string to be used with pt-online-schema-change.
Constructor Details
#initialize(connection_data) ⇒ ConnectionDetails
Constructor
9 10 11 |
# File 'lib/arrival/connection_details.rb', line 9 def initialize(connection_data) @connection_data = connection_data end |
Instance Method Details
#database ⇒ String
TODO: Doesn’t the abstract adapter already handle this somehow? Returns the database name. If PERCONA_DB_NAME is passed its value will be used instead
Returns the database name
28 29 30 |
# File 'lib/arrival/connection_details.rb', line 28 def database ENV.fetch('PERCONA_DB_NAME', connection_data[:database]) end |
#host_argument ⇒ String
Returns the host fragment of the details string, adds ssl options if needed
46 47 48 49 50 51 52 |
# File 'lib/arrival/connection_details.rb', line 46 def host_argument host_string = host if ssl_ca.present? host_string += ";mysql_ssl=1;mysql_ssl_client_ca=#{ssl_ca}" end "-h \"#{host_string}\"" end |
#password_argument ⇒ String
Returns the password fragment of the details string if a password is passed
35 36 37 38 39 40 41 |
# File 'lib/arrival/connection_details.rb', line 35 def password_argument if password.present? %(--password #{Shellwords.escape(password)} ) else '' end end |
#to_s ⇒ String
Returns the details formatted as an string to be used with pt-online-schema-change. It follows the mysql client’s format.
17 18 19 |
# File 'lib/arrival/connection_details.rb', line 17 def to_s @to_s ||= "#{host_argument} -P #{port} -u #{user} #{password_argument}" end |