Sha256: 1078760d3e0e59e18a0310c6b8de3340dcfb82385bdde87596bec9b5acf287d5
Contents?: true
Size: 1.57 KB
Versions: 17
Compression:
Stored size: 1.57 KB
Contents
# frozen_string_literal: true module ThinkingSphinx::ActiveRecord::DatabaseAdapters class << self attr_accessor :default def adapter_for(model) return default.new(model) if default adapter = adapter_type_for(model) klass = case adapter when :mysql MySQLAdapter when :postgresql PostgreSQLAdapter else raise ThinkingSphinx::InvalidDatabaseAdapter, "Invalid adapter '#{adapter}': Thinking Sphinx only supports MySQL and PostgreSQL." end klass.new model end def adapter_type_for(model) class_name = model.connection.class.name case class_name.split('::').last when 'MysqlAdapter', 'Mysql2Adapter' :mysql when 'PostgreSQLAdapter' :postgresql when 'JdbcAdapter' adapter_type_for_jdbc(model) else class_name end end def adapter_type_for_jdbc(model) case adapter = model.connection.config[:adapter] when 'jdbcmysql' :mysql when 'jdbcpostgresql' :postgresql when 'jdbc' adapter_type_for_jdbc_plain(adapter, model.connection.config[:url]) else adapter end end def adapter_type_for_jdbc_plain(adapter, url) return adapter unless match = /^jdbc:(?<adapter>mysql|postgresql):\/\//.match(url) match[:adapter].to_sym end end end require 'thinking_sphinx/active_record/database_adapters/abstract_adapter' require 'thinking_sphinx/active_record/database_adapters/mysql_adapter' require 'thinking_sphinx/active_record/database_adapters/postgresql_adapter'
Version data entries
17 entries across 17 versions & 1 rubygems