Sha256: b89aeb6e2e0108d8aae44e6f29e930b7bdcda2d174db0e2fd59980554dafd395

Contents?: true

Size: 917 Bytes

Versions: 2

Compression:

Stored size: 917 Bytes

Contents

module ActsAsTaggableOn
  module Utils

    def connection
      ::ActiveRecord::Base.connection
    end

    def using_postgresql?
      connection && connection.adapter_name == 'PostgreSQL'
    end

    def using_sqlite?
      connection && connection.adapter_name == 'SQLite'
    end

    def using_mysql?
      #We should probably use regex for mysql to support prehistoric adapters
      connection && connection.adapter_name == 'Mysql2'
    end

    def using_case_insensitive_collation?
      using_mysql? && ::ActiveRecord::Base.connection.collation =~ /_ci\Z/
    end

    def sha_prefix(string)
      Digest::SHA1.hexdigest("#{string}#{rand}")[0..6]
    end

    private

    def like_operator
      using_postgresql? ? 'ILIKE' : 'LIKE'
    end

    # escape _ and % characters in strings, since these are wildcards in SQL.
    def escape_like(str)
      str.gsub(/[!%_]/) { |x| '!' + x }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acts-as-taggable-on-3.1.1 lib/acts_as_taggable_on/utils.rb
acts-as-taggable-on-3.1.0 lib/acts_as_taggable_on/utils.rb