Class: Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tag
- Includes:
- ActsAsTaggableOn::ActiveRecord::Backports, TagCustomisations, TagValidations
- 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
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/acts_as_taggable_on/tag.rb', line 41 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:
37 38 39 |
# File 'lib/acts_as_taggable_on/tag.rb', line 37 def self.find_or_create_with_like_by_name(name) named_like(name).first || create(:name => name) end |
.named(name) ⇒ Object
SCOPES:
19 20 21 |
# File 'lib/acts_as_taggable_on/tag.rb', line 19 def self.named(name) where(["name LIKE ?", name]) end |
.named_any(list) ⇒ Object
23 24 25 |
# File 'lib/acts_as_taggable_on/tag.rb', line 23 def self.named_any(list) where(list.map { |tag| sanitize_sql(["name LIKE ?", tag.to_s]) }.join(" OR ")) end |
.named_like(name) ⇒ Object
27 28 29 |
# File 'lib/acts_as_taggable_on/tag.rb', line 27 def self.named_like(name) where(["name LIKE ?", "%#{name}%"]) end |
.named_like_any(list) ⇒ Object
31 32 33 |
# File 'lib/acts_as_taggable_on/tag.rb', line 31 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:
55 56 57 |
# File 'lib/acts_as_taggable_on/tag.rb', line 55 def ==(object) super || (object.is_a?(Tag) && name == object.name) end |
#count ⇒ Object
63 64 65 |
# File 'lib/acts_as_taggable_on/tag.rb', line 63 def count read_attribute(:count).to_i end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/acts_as_taggable_on/tag.rb', line 59 def to_s name end |