Class: ActsAsTaggableOn::Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActsAsTaggableOn::Tag
- Includes:
- Utils
- Defined in:
- app/models/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
- #safe_name ⇒ Object
- #to_s ⇒ Object
Methods included from Utils
Class Method Details
.find_or_create_all_with_like_by_name(*list) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 43 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:
39 40 41 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 39 def self.find_or_create_with_like_by_name(name) named_like(name).first || create(:name => name) end |
.named(name) ⇒ Object
SCOPES:
21 22 23 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 21 def self.named(name) where(["name #{like_operator} ? ESCAPE '!'", escape_like(name)]) end |
.named_any(list) ⇒ Object
25 26 27 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 25 def self.named_any(list) where(list.map { |tag| sanitize_sql(["name #{like_operator} ? ESCAPE '!'", escape_like(tag.to_s)]) }.join(" OR ")) end |
.named_like(name) ⇒ Object
29 30 31 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 29 def self.named_like(name) where(["name #{like_operator} ? ESCAPE '!'", "%#{escape_like(name)}%"]) end |
.named_like_any(list) ⇒ Object
33 34 35 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 33 def self.named_like_any(list) where(list.map { |tag| sanitize_sql(["name #{like_operator} ? ESCAPE '!'", "%#{escape_like(tag.to_s)}%"]) }.join(" OR ")) end |
Instance Method Details
#==(object) ⇒ Object
INSTANCE METHODS:
60 61 62 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 60 def ==(object) super || (object.is_a?(Tag) && name == object.name) end |
#count ⇒ Object
68 69 70 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 68 def count read_attribute(:count).to_i end |
#safe_name ⇒ Object
72 73 74 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 72 def safe_name name.gsub(/[^a-zA-Z0-9]/, '') end |
#to_s ⇒ Object
64 65 66 |
# File 'app/models/acts_as_taggable_on/tag.rb', line 64 def to_s name end |