Class: Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tag
- 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
SCOPES:.
- .named_any(list) ⇒ Object
- .named_like(name) ⇒ Object
- .named_like_any(list) ⇒ Object
Instance Method Summary collapse
-
#==(object) ⇒ Object
INSTANCE METHODS:.
- #count ⇒ Object
- #to_s ⇒ Object
Methods included from ActsAsTaggableOn::ActiveRecord::Backports
Class Method Details
.find_or_create_all_with_like_by_name(*list) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/acts_as_taggable_on/tag.rb', line 39 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 { |name| .any? { |tag| tag.name.mb_chars.downcase == name.mb_chars.downcase } } = new_tag_names.map { |name| Tag.create(:name => name) } + end |
.find_or_create_with_like_by_name(name) ⇒ Object
CLASS METHODS:
35 36 37 |
# File 'lib/acts_as_taggable_on/tag.rb', line 35 def self.find_or_create_with_like_by_name(name) named_like(name).first || create(:name => name) end |
.named(name) ⇒ Object
SCOPES:
17 18 19 |
# File 'lib/acts_as_taggable_on/tag.rb', line 17 def self.named(name) where(["name LIKE ?", name]) end |
.named_any(list) ⇒ Object
21 22 23 |
# File 'lib/acts_as_taggable_on/tag.rb', line 21 def self.named_any(list) where(list.map { |tag| sanitize_sql(["name LIKE ?", tag.to_s]) }.join(" OR ")) end |
.named_like(name) ⇒ Object
25 26 27 |
# File 'lib/acts_as_taggable_on/tag.rb', line 25 def self.named_like(name) where(["name LIKE ?", "%#{name}%"]) end |
.named_like_any(list) ⇒ Object
29 30 31 |
# File 'lib/acts_as_taggable_on/tag.rb', line 29 def self.named_like_any(list) where(list.map { |tag| sanitize_sql(["name LIKE ?", "%#{tag.to_s}%"]) }.join(" OR ")) end |
Instance Method Details
#==(object) ⇒ Object
INSTANCE METHODS:
53 54 55 |
# File 'lib/acts_as_taggable_on/tag.rb', line 53 def ==(object) super || (object.is_a?(Tag) && name == object.name) end |
#count ⇒ Object
61 62 63 |
# File 'lib/acts_as_taggable_on/tag.rb', line 61 def count read_attribute(:count).to_i end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/acts_as_taggable_on/tag.rb', line 57 def to_s name end |