Module: ActsAsTaggableOn::Utils

Defined in:
lib/acts_as_taggable_on/utils.rb

Class Method Summary collapse

Class Method Details

.active_record4?Boolean



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

def active_record4?
  ::ActiveRecord::VERSION::MAJOR == 4
end

.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.



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

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

.like_operatorObject



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

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

.sha_prefix(string) ⇒ Object



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

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

.using_mysql?Boolean



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

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

.using_postgresql?Boolean



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

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