Sha256: 3bd7818f03a67d6c110dad9124bf71174b0d3db48ea66a0a1b25dc336dcaa41e

Contents?: true

Size: 640 Bytes

Versions: 2

Compression:

Stored size: 640 Bytes

Contents

class Gutentag::Tag < ActiveRecord::Base
  self.table_name = 'gutentag_tags'

  has_many :taggings, :class_name => 'Gutentag::Tagging',
    :dependent => :destroy

  attr_accessible :name if ActiveRecord::VERSION::MAJOR == 3

  scope :by_weight, ->{ order('gutentag_tags.taggings_count DESC') }

  Gutentag.tag_validations.call self

  before_validation :normalise_name

  def self.find_by_name(name)
    where(:name => Gutentag.normaliser.call(name)).first
  end

  def self.find_or_create(name)
    find_by_name(name) || create(:name => name)
  end

  private

  def normalise_name
    self.name = Gutentag.normaliser.call name
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gutentag-0.9.0 app/models/gutentag/tag.rb
gutentag-0.8.0 app/models/gutentag/tag.rb