Skip to content

Instantly share code, notes, and snippets.

@hvardhanx
Created January 1, 2017 10:06
Show Gist options
  • Save hvardhanx/cc1066b6cf9faf9da570647e8af1f0db to your computer and use it in GitHub Desktop.
Save hvardhanx/cc1066b6cf9faf9da570647e8af1f0db to your computer and use it in GitHub Desktop.
Test
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">
@hvardhanx
Copy link
Author

Although I was able to use @db_type instance var. But, it returns SSHScan::DatabaseConfig class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment