Sha256: d74a999d492113355f32df40fe58acfa5963519a4ac4533582a1c08622bd645d

Contents?: true

Size: 681 Bytes

Versions: 2

Compression:

Stored size: 681 Bytes

Contents

# frozen_string_literal: true

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, lambda { 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-1.1.0 app/models/gutentag/tag.rb
gutentag-1.0.0 app/models/gutentag/tag.rb