Module: ActsAsTaggableOn::Utils
- Defined in:
- lib/acts-as-taggable-on/utils.rb
Class Method Summary collapse
-
.connection ⇒ Object
Use ActsAsTaggableOn::Tag connection.
-
.escape_like(str) ⇒ Object
escape _ and % characters in strings, since these are wildcards in SQL.
- .like_operator ⇒ Object
- .sha_prefix(string) ⇒ Object
- .using_mysql? ⇒ Boolean
- .using_postgresql? ⇒ Boolean
Class Method Details
.connection ⇒ Object
Use ActsAsTaggableOn::Tag connection
9 10 11 |
# File 'lib/acts-as-taggable-on/utils.rb', line 9 def connection ActsAsTaggableOn::Tag.connection end |
.escape_like(str) ⇒ Object
escape _ and % characters in strings, since these are wildcards in SQL.
30 31 32 |
# File 'lib/acts-as-taggable-on/utils.rb', line 30 def escape_like(str) str.gsub(/[!%_]/) { |x| "!#{x}" } end |
.like_operator ⇒ Object
25 26 27 |
# File 'lib/acts-as-taggable-on/utils.rb', line 25 def like_operator using_postgresql? ? 'ILIKE' : 'LIKE' end |
.sha_prefix(string) ⇒ Object
21 22 23 |
# File 'lib/acts-as-taggable-on/utils.rb', line 21 def sha_prefix(string) Digest::SHA1.hexdigest(string)[0..6] end |
.using_mysql? ⇒ Boolean
17 18 19 |
# File 'lib/acts-as-taggable-on/utils.rb', line 17 def using_mysql? connection && connection.adapter_name == 'Mysql2' end |
.using_postgresql? ⇒ Boolean
13 14 15 |
# File 'lib/acts-as-taggable-on/utils.rb', line 13 def using_postgresql? connection && %w[PostgreSQL PostGIS].include?(connection.adapter_name) end |