Sha256: b30014f94ed7857639a8e1a0f7050df18a42eb93ec4039e7132e5e70e7582ce3

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

class JSONColumn
  include ActiveRecord::ConnectionAdapters

  def self.call
    new.call
  end

  def call
    sphinx? && postgresql? && column?
  end

  private

  def column?
    (
      ActiveRecord::ConnectionAdapters.constants.include?(:PostgreSQLAdapter) &&
      PostgreSQLAdapter.constants.include?(:TableDefinition) &&
      PostgreSQLAdapter::TableDefinition.instance_methods.include?(:json)
    ) || (
      ActiveRecord::ConnectionAdapters.constants.include?(:PostgreSQL) &&
      PostgreSQL.constants.include?(:ColumnMethods) &&
      PostgreSQL::ColumnMethods.instance_methods.include?(:json)
    )
  end

  def postgresql?
    ENV['DATABASE'] == 'postgresql'
  end

  def sphinx?
    ENV['SPHINX_VERSION'].nil? || ENV['SPHINX_VERSION'].to_f > 2.0
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-3.3.0 spec/support/json_column.rb