Module: ActsAsTaggableOn::Utils

Defined in:
lib/acts_as_taggable_on/utils.rb

Class Method Summary collapse

Class Method Details

.connectionObject

Use ActsAsTaggableOn::Tag connection



7
8
9
# File 'lib/acts_as_taggable_on/utils.rb', line 7

def connection
  ActsAsTaggableOn::Tag.connection
end

.escape_like(str) ⇒ Object

escape _ and % characters in strings, since these are wildcards in SQL.



32
33
34
# File 'lib/acts_as_taggable_on/utils.rb', line 32

def escape_like(str)
  str.gsub(/[!%_]/) { |x| '!' + x }
end

.legacy_activerecord?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/acts_as_taggable_on/utils.rb', line 27

def legacy_activerecord?
  ActiveRecord.version <= Gem::Version.new('5.3.0')
end

.like_operatorObject



23
24
25
# File 'lib/acts_as_taggable_on/utils.rb', line 23

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

.sha_prefix(string) ⇒ Object



19
20
21
# File 'lib/acts_as_taggable_on/utils.rb', line 19

def sha_prefix(string)
  Digest::SHA1.hexdigest(string)[0..6]
end

.using_mysql?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/acts_as_taggable_on/utils.rb', line 15

def using_mysql?
  connection && connection.adapter_name == 'Mysql2'
end

.using_postgresql?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/acts_as_taggable_on/utils.rb', line 11

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