Module: MakeTaggable::Utils
- Defined in:
- lib/make_taggable/utils.rb
Class Method Summary collapse
- .connection ⇒ Object
-
.escape_like(str) ⇒ Object
escape _ and % characters in strings, since these are wildcards in SQL.
- .legacy_activerecord? ⇒ Boolean
- .like_operator ⇒ Object
- .sha_prefix(string) ⇒ Object
- .using_mysql? ⇒ Boolean
- .using_postgresql? ⇒ Boolean
Class Method Details
.connection ⇒ Object
4 5 6 |
# File 'lib/make_taggable/utils.rb', line 4 def connection MakeTaggable::Tag.connection end |
.escape_like(str) ⇒ Object
escape _ and % characters in strings, since these are wildcards in SQL.
29 30 31 |
# File 'lib/make_taggable/utils.rb', line 29 def escape_like(str) str.gsub(/[!%_]/) { |x| "!" + x } end |
.legacy_activerecord? ⇒ Boolean
24 25 26 |
# File 'lib/make_taggable/utils.rb', line 24 def legacy_activerecord? ActiveRecord.version <= Gem::Version.new("5.3.0") end |
.like_operator ⇒ Object
20 21 22 |
# File 'lib/make_taggable/utils.rb', line 20 def like_operator using_postgresql? ? "ILIKE" : "LIKE" end |
.sha_prefix(string) ⇒ Object
16 17 18 |
# File 'lib/make_taggable/utils.rb', line 16 def sha_prefix(string) Digest::SHA1.hexdigest(string)[0..6] end |
.using_mysql? ⇒ Boolean
12 13 14 |
# File 'lib/make_taggable/utils.rb', line 12 def using_mysql? connection && connection.adapter_name == "Mysql2" end |
.using_postgresql? ⇒ Boolean
8 9 10 |
# File 'lib/make_taggable/utils.rb', line 8 def using_postgresql? connection && connection.adapter_name == "PostgreSQL" end |