Created
January 1, 2017 10:06
-
-
Save hvardhanx/cc1066b6cf9faf9da570647e8af1f0db to your computer and use it in GitHub Desktop.
Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initialize(opts = {}) | |
@db_type = if !opts || opts.empty? | |
'sqlite' | |
else | |
opts['database']['type'] | |
end | |
set_database | |
end | |
def self.from_config_file | |
@@db_path = File.join(Dir.pwd, '/config/database/database_config.yml') | |
db_opts = YAML.load_file(@@db_path) | |
SSHScan::DatabaseConfig.new(db_opts) | |
end | |
def set_database | |
if @db_type.eql? 'mongodb' | |
return SSHScan::Database::MongoDb.from_config_file(@@db_path) | |
elsif @db_type.eql? 'sqlite' | |
return SSHScan::Database::SQLite.from_config_file(@@db_path) | |
end | |
end | |
# Set this in api.rb | |
set :db, SSHScan::DatabaseConfig.from_config_file | |
# It shows error: | |
# NoMethodError - undefined method `add_scan' for #<SSHScan::DatabaseConfig:0x000000022638b8 @db_type="sqlite"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Although I was able to use
@db_type
instance var. But, it returnsSSHScan::DatabaseConfig
class.