Module: ActiveRecord::ConnectionHandling
- Defined in:
- lib/active_record/connection_adapters/litedb_adapter.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#litedb_connection(config) ⇒ Object
9 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 |
# File 'lib/active_record/connection_adapters/litedb_adapter.rb', line 9 def litedb_connection(config) config = config.symbolize_keys # Require database. unless config[:database] raise ArgumentError, "No database file specified. Missing argument: database" end # Allow database path relative to Rails.root, but only if the database # path is not the special path that tells sqlite to build a database only # in memory. if config[:database] != ":memory:" && !config[:database].to_s.start_with?("file:") config[:database] = File.(config[:database], Rails.root) if defined?(Rails.root) dirname = File.dirname(config[:database]) Dir.mkdir(dirname) unless File.directory?(dirname) end db = ::Litedb.new( config[:database].to_s, config.merge(results_as_hash: true) ) ConnectionAdapters::LitedbAdapter.new(db, logger, nil, config) rescue Errno::ENOENT => error if error..include?("No such file or directory") raise ActiveRecord::NoDatabaseError else raise end end |