Module: Eksa::Database
- Defined in:
- lib/eksa/database.rb
Class Method Summary collapse
Class Method Details
.adapter ⇒ Object
11 12 13 |
# File 'lib/eksa/database.rb', line 11 def self.adapter @adapter ||= create_adapter end |
.create_adapter ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/eksa/database.rb', line 19 def self.create_adapter config = load_config type = config.dig('database', 'type') || 'sqlite' case type when 'mongo', 'mongodb' require_relative 'database/mongo_adapter' mongo_config = config.dig('database', 'mongodb') || {} # Prioritize Environment Variable for Security env_uri = ENV['EKSA_MONGODB_URI'] || ENV['MONGODB_URI'] mongo_config['uri'] = env_uri if env_uri MongoAdapter.new(mongo_config) else require_relative 'database/sqlite_adapter' SqliteAdapter.new(config.dig('database', 'sqlite')) end end |
.load_config ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/eksa/database.rb', line 39 def self.load_config config_path = File.join(Dir.pwd, '.eksa.json') return {} unless File.exist?(config_path) JSON.parse(File.read(config_path)) rescue {} end |
.reset_adapter ⇒ Object
15 16 17 |
# File 'lib/eksa/database.rb', line 15 def self.reset_adapter @adapter = nil end |