class Dataflow::Adapters::Settings
Attributes
adapter_type[RW]
connection_uri[RW]
dataset_name[RW]
db_host[RW]
db_name[RW]
db_password[RW]
db_port[RW]
db_user[RW]
indexes[RW]
read_dataset_name[RW]
schema[RW]
write_dataset_name[RW]
Public Class Methods
new(data_node: nil, connection_uri: nil, db_name: nil, db_host: nil, db_port: nil, db_user: nil, db_password: nil, dataset_name: nil, indexes: nil, adapter_type: nil, schema: nil)
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 10 def initialize(data_node: nil, connection_uri: nil, db_name: nil, db_host: nil, db_port: nil, db_user: nil, db_password: nil, dataset_name: nil, indexes: nil, adapter_type: nil, schema: nil) @connection_uri = connection_uri # first try to set the options based on the data node settings if data_node.present? @db_name = data_node.db_name @db_host = data_node.db_host @db_port = data_node.db_port @db_user = data_node.db_user @db_password = data_node.db_password @dataset_name = data_node.name @read_dataset_name = data_node.read_dataset_name @write_dataset_name = data_node.write_dataset_name @indexes = data_node.indexes @schema = data_node.schema end # override if needed @db_name ||= db_name @db_host ||= db_host @db_port ||= db_port @db_user ||= db_user @db_password ||= db_password @dataset_name ||= dataset_name @read_dataset_name ||= dataset_name @write_dataset_name ||= dataset_name @indexes ||= indexes @adapter_type ||= adapter_type @schema ||= schema end
Public Instance Methods
connection_uri_or_default()
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 64 def connection_uri_or_default return @connection_uri if @connection_uri.present? send("#{@adapter_type}_default_connection_uri") end
mongodb_default_connection_uri()
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 70 def mongodb_default_connection_uri set_mongodb_defaults_if_needed! # if user/password are empty, the user_password will be empty as well user_password = @db_user user_password += ":#{@db_password}" if @db_password.present? user_password += '@' if user_password.present? # [username:password@]host1[:port1] "#{user_password}#{@db_host}:#{@db_port}" end
mysql_default_connection_uri()
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 82 def mysql_default_connection_uri set_mysql_defaults_if_needed! sql_default_connection_uri('mysql2') end
postgresql_default_connection_uri()
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 87 def postgresql_default_connection_uri set_postgresql_defaults_if_needed! sql_default_connection_uri('postgresql') end
set_mongodb_defaults_if_needed!()
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 43 def set_mongodb_defaults_if_needed! @db_host ||= ENV['MOJACO_MONGO_ADDRESS'] || '127.0.0.1' @db_port ||= ENV['MOJACO_MONGO_PORT'] || '27017' @db_user ||= ENV['MOJACO_MONGO_USER'] @db_password ||= ENV['MOJACO_MONGO_USER'] end
set_mysql_defaults_if_needed!()
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 57 def set_mysql_defaults_if_needed! @db_host ||= ENV['MOJACO_MYSQL_ADDRESS'] || '127.0.0.1' @db_port ||= ENV['MOJACO_MYSQL_PORT'] || '3306' @db_user ||= ENV['MOJACO_MYSQL_USER'] @db_password ||= ENV['MOJACO_MYSQL_PASSWORD'] end
set_postgresql_defaults_if_needed!()
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 50 def set_postgresql_defaults_if_needed! @db_host ||= ENV['MOJACO_POSTGRESQL_ADDRESS'] || '127.0.0.1' @db_port ||= ENV['MOJACO_POSTGRESQL_PORT'] || '5432' @db_user ||= ENV['MOJACO_POSTGRESQL_USER'] @db_password ||= ENV['MOJACO_POSTGRESQL_PASSWORD'] end
sql_default_connection_uri(scheme)
click to toggle source
# File lib/dataflow/adapters/settings.rb, line 92 def sql_default_connection_uri(scheme) user_password = @db_user user_password += ":#{@db_password}" if @db_password.present? "#{scheme}://#{user_password}@#{@db_host}:#{@db_port}" end