Sha256: 01b1de60920887793a7385ddfb7f00e31e9996e926d854990e139d29e0e7dbfb

Contents?: true

Size: 817 Bytes

Versions: 7

Compression:

Stored size: 817 Bytes

Contents

class Tag < ActiveRecord::Base
  has_many :taggings, :dependent => :destroy
  
  validates_presence_of :name
  validates_uniqueness_of :name
  
  named_scope :named, lambda { |name| { :conditions => ["name = ?", name] } }
  named_scope :named_like, lambda { |name| { :conditions => ["name LIKE ?", "%#{name}%"] } }
  named_scope :named_like_any, lambda { |list| { :conditions => list.map { |tag| sanitize_sql(["name LIKE ?", tag.to_s]) }.join(" OR ") } }
  
  # LIKE is used for cross-database case-insensitivity
  def self.find_or_create_with_like_by_name(name)
    find(:first, :conditions => ["name LIKE ?", name]) || create(:name => name)
  end
  
  def ==(object)
    super || (object.is_a?(Tag) && name == object.name)
  end
  
  def to_s
    name
  end
  
  def count
    read_attribute(:count).to_i
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
bbenezech-acts-as-taggable-on-0.0.4 lib/acts_as_taggable_on/tag.rb
bbenezech-acts-as-taggable-on-0.0.3 lib/acts_as_taggable_on/tag.rb
acts-as-taggable-on-1.0.17 lib/acts_as_taggable_on/tag.rb
bbenezech-acts-as-taggable-on-0.0.2 lib/acts_as_taggable_on/tag.rb
acts-as-taggable-on-1.0.16 lib/acts_as_taggable_on/tag.rb
acts-as-taggable-on-1.0.15 lib/acts_as_taggable_on/tag.rb
acts-as-taggable-on-1.0.14 lib/acts_as_taggable_on/tag.rb