Class: Dataflow::Adapters::Settings
- Inherits:
-
Object
- Object
- Dataflow::Adapters::Settings
- Defined in:
- lib/dataflow/adapters/settings.rb
Instance Attribute Summary collapse
-
#adapter_type ⇒ Object
Returns the value of attribute adapter_type.
-
#connection_uri ⇒ Object
Returns the value of attribute connection_uri.
-
#dataset_name ⇒ Object
Returns the value of attribute dataset_name.
-
#db_host ⇒ Object
Returns the value of attribute db_host.
-
#db_name ⇒ Object
Returns the value of attribute db_name.
-
#db_password ⇒ Object
Returns the value of attribute db_password.
-
#db_port ⇒ Object
Returns the value of attribute db_port.
-
#db_user ⇒ Object
Returns the value of attribute db_user.
-
#indexes ⇒ Object
Returns the value of attribute indexes.
-
#read_dataset_name ⇒ Object
Returns the value of attribute read_dataset_name.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#write_dataset_name ⇒ Object
Returns the value of attribute write_dataset_name.
Instance Method Summary collapse
- #connection_uri_or_default ⇒ Object
-
#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) ⇒ Settings
constructor
A new instance of Settings.
- #mongodb_default_connection_uri ⇒ Object
- #mysql_default_connection_uri ⇒ Object
- #postgresql_default_connection_uri ⇒ Object
- #set_mongodb_defaults_if_needed! ⇒ Object
- #set_mysql_defaults_if_needed! ⇒ Object
- #set_postgresql_defaults_if_needed! ⇒ Object
- #sql_default_connection_uri(scheme) ⇒ Object
Constructor Details
#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) ⇒ Settings
Returns a new instance of Settings.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |
Instance Attribute Details
#adapter_type ⇒ Object
Returns the value of attribute adapter_type.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def adapter_type @adapter_type end |
#connection_uri ⇒ Object
Returns the value of attribute connection_uri.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def connection_uri @connection_uri end |
#dataset_name ⇒ Object
Returns the value of attribute dataset_name.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def dataset_name @dataset_name end |
#db_host ⇒ Object
Returns the value of attribute db_host.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def db_host @db_host end |
#db_name ⇒ Object
Returns the value of attribute db_name.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def db_name @db_name end |
#db_password ⇒ Object
Returns the value of attribute db_password.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def db_password @db_password end |
#db_port ⇒ Object
Returns the value of attribute db_port.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def db_port @db_port end |
#db_user ⇒ Object
Returns the value of attribute db_user.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def db_user @db_user end |
#indexes ⇒ Object
Returns the value of attribute indexes.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def indexes @indexes end |
#read_dataset_name ⇒ Object
Returns the value of attribute read_dataset_name.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def read_dataset_name @read_dataset_name end |
#schema ⇒ Object
Returns the value of attribute schema.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def schema @schema end |
#write_dataset_name ⇒ Object
Returns the value of attribute write_dataset_name.
5 6 7 |
# File 'lib/dataflow/adapters/settings.rb', line 5 def write_dataset_name @write_dataset_name end |
Instance Method Details
#connection_uri_or_default ⇒ Object
64 65 66 67 68 |
# 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 ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# 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 ⇒ Object
82 83 84 85 |
# 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 ⇒ Object
87 88 89 90 |
# 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! ⇒ Object
43 44 45 46 47 48 |
# 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! ⇒ Object
57 58 59 60 61 62 |
# 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! ⇒ Object
50 51 52 53 54 55 |
# 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) ⇒ Object
92 93 94 95 96 97 |
# 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 |