From 68fced73fc5d0d1a60b3f2e4c88402c1af227785 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Wed, 29 Apr 2020 10:30:23 +0200 Subject: [PATCH] M #-: make onedb code more readable (#4625) --- src/onedb/onedb.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/onedb/onedb.rb b/src/onedb/onedb.rb index 36308263cb..910e7b62cd 100644 --- a/src/onedb/onedb.rb +++ b/src/onedb/onedb.rb @@ -22,10 +22,12 @@ LOG_TIME = false class OneDB attr_accessor :backend + CONNECTION_PARAMETERS = %i[server port user password db_name] + def initialize(ops) - if ops[:backend].nil? && ops[:server].nil? && ops[:port].nil? && ops[:user].nil? && ops[:password].nil? && ops[:db_name].nil? + if ops[:backend].nil? && CONNECTION_PARAMETERS.all? {|s| ops[s].nil? } ops = read_credentials(ops) - elsif ops[:backend].nil? and (!ops[:server].nil? || !ops[:port].nil? || !ops[:user].nil? || !ops[:password].nil? || !ops[:db_name].nil? || !ops[:encoding].nil?) + elsif ops[:backend].nil? && CONNECTION_PARAMETERS.one? {|s| !ops[s].nil? } # Set MySQL backend as default if any connection option is provided and --type is not ops[:backend] = :mysql end @@ -100,7 +102,7 @@ class OneDB end def read_credentials(ops) - begin + begin gem 'augeas', '~> 0.6' require 'augeas' rescue Gem::LoadError