Module: ActsAsTaggableOn::Utils
- Defined in:
- lib/acts_as_taggable_on/utils.rb
Class Method Summary collapse
- .active_record42? ⇒ Boolean
- .active_record4? ⇒ Boolean
-
.connection ⇒ Object
Use ActsAsTaggableOn::Tag connection.
-
.escape_like(str) ⇒ Object
escape _ and % characters in strings, since these are wildcards in SQL.
- .like_operator ⇒ Object
- .postgresql_support_json? ⇒ Boolean
- .postgresql_version ⇒ Object
- .sha_prefix(string) ⇒ Object
- .supports_concurrency? ⇒ Boolean
- .using_case_insensitive_collation? ⇒ Boolean
- .using_mysql? ⇒ Boolean
- .using_postgresql? ⇒ Boolean
- .using_sqlite? ⇒ Boolean
Class Method Details
.active_record42? ⇒ Boolean
48 49 50 |
# File 'lib/acts_as_taggable_on/utils.rb', line 48 def active_record42? active_record4? && ::ActiveRecord::VERSION::MINOR >= 2 end |
.active_record4? ⇒ Boolean
44 45 46 |
# File 'lib/acts_as_taggable_on/utils.rb', line 44 def active_record4? ::ActiveRecord::VERSION::MAJOR == 4 end |
.connection ⇒ Object
Use ActsAsTaggableOn::Tag connection
5 6 7 |
# File 'lib/acts_as_taggable_on/utils.rb', line 5 def connection ActsAsTaggableOn::Tag.connection end |
.escape_like(str) ⇒ Object
escape _ and % characters in strings, since these are wildcards in SQL.
57 58 59 |
# File 'lib/acts_as_taggable_on/utils.rb', line 57 def escape_like(str) str.gsub(/[!%_]/) { |x| '!' + x } end |
.like_operator ⇒ Object
52 53 54 |
# File 'lib/acts_as_taggable_on/utils.rb', line 52 def like_operator using_postgresql? ? 'ILIKE' : 'LIKE' end |
.postgresql_support_json? ⇒ Boolean
19 20 21 |
# File 'lib/acts_as_taggable_on/utils.rb', line 19 def postgresql_support_json? postgresql_version >= 9.2 end |
.postgresql_version ⇒ Object
13 14 15 16 17 |
# File 'lib/acts_as_taggable_on/utils.rb', line 13 def postgresql_version if using_postgresql? connection.execute('SHOW SERVER_VERSION').first['server_version'].to_f end end |
.sha_prefix(string) ⇒ Object
40 41 42 |
# File 'lib/acts_as_taggable_on/utils.rb', line 40 def sha_prefix(string) Digest::SHA1.hexdigest("#{string}#{rand}")[0..6] end |
.supports_concurrency? ⇒ Boolean
36 37 38 |
# File 'lib/acts_as_taggable_on/utils.rb', line 36 def supports_concurrency? !using_sqlite? end |
.using_case_insensitive_collation? ⇒ Boolean
32 33 34 |
# File 'lib/acts_as_taggable_on/utils.rb', line 32 def using_case_insensitive_collation? using_mysql? && connection.collation =~ /_ci\Z/ end |
.using_mysql? ⇒ Boolean
27 28 29 30 |
# File 'lib/acts_as_taggable_on/utils.rb', line 27 def using_mysql? #We should probably use regex for mysql to support prehistoric adapters connection && connection.adapter_name == 'Mysql2' end |
.using_postgresql? ⇒ Boolean
9 10 11 |
# File 'lib/acts_as_taggable_on/utils.rb', line 9 def using_postgresql? connection && connection.adapter_name == 'PostgreSQL' end |
.using_sqlite? ⇒ Boolean
23 24 25 |
# File 'lib/acts_as_taggable_on/utils.rb', line 23 def using_sqlite? connection && connection.adapter_name == 'SQLite' end |