Class: ActsAsTaggableOn::Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActsAsTaggableOn::Tag
- Includes:
- ActiveRecord::Backports
- Defined in:
- lib/acts_as_taggable_on/tag.rb
Class Method Summary collapse
- .find_or_create_all_with_like_by_name(*list) ⇒ Object
-
.find_or_create_with_like_by_name(name) ⇒ Object
CLASS METHODS:.
- .named(name) ⇒ Object
- .named_any(list) ⇒ Object
- .named_like(name) ⇒ Object
- .named_like_any(list) ⇒ Object
-
.using_postgresql? ⇒ Boolean
SCOPES:.
Instance Method Summary collapse
-
#==(object) ⇒ Object
INSTANCE METHODS:.
- #count ⇒ Object
- #to_s ⇒ Object
Methods included from ActiveRecord::Backports
Class Method Details
.find_or_create_all_with_like_by_name(*list) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/acts_as_taggable_on/tag.rb', line 44 def self.find_or_create_all_with_like_by_name(*list) list = [list].flatten return [] if list.empty? = Tag.named_any(list).all new_tag_names = list.reject do |name| name = comparable_name(name) .any? { |tag| comparable_name(tag.name) == name } end = new_tag_names.map { |name| Tag.create(:name => name) } + end |
.find_or_create_with_like_by_name(name) ⇒ Object
CLASS METHODS:
40 41 42 |
# File 'lib/acts_as_taggable_on/tag.rb', line 40 def self.find_or_create_with_like_by_name(name) named_like(name).first || create(:name => name) end |
.named(name) ⇒ Object
22 23 24 |
# File 'lib/acts_as_taggable_on/tag.rb', line 22 def self.named(name) where(["name #{like_operator} ?", name]) end |
.named_any(list) ⇒ Object
26 27 28 |
# File 'lib/acts_as_taggable_on/tag.rb', line 26 def self.named_any(list) where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", tag.to_s]) }.join(" OR ")) end |
.named_like(name) ⇒ Object
30 31 32 |
# File 'lib/acts_as_taggable_on/tag.rb', line 30 def self.named_like(name) where(["name #{like_operator} ?", "%#{name}%"]) end |
.named_like_any(list) ⇒ Object
34 35 36 |
# File 'lib/acts_as_taggable_on/tag.rb', line 34 def self.named_like_any(list) where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", "%#{tag.to_s}%"]) }.join(" OR ")) end |
.using_postgresql? ⇒ Boolean
SCOPES:
18 19 20 |
# File 'lib/acts_as_taggable_on/tag.rb', line 18 def self.using_postgresql? connection.adapter_name == 'PostgreSQL' end |
Instance Method Details
#==(object) ⇒ Object
INSTANCE METHODS:
61 62 63 |
# File 'lib/acts_as_taggable_on/tag.rb', line 61 def ==(object) super || (object.is_a?(Tag) && name == object.name) end |
#count ⇒ Object
69 70 71 |
# File 'lib/acts_as_taggable_on/tag.rb', line 69 def count read_attribute(:count).to_i end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/acts_as_taggable_on/tag.rb', line 65 def to_s name end |