Sha256: 23dc0e22ab5d44ac4948e7e5d71bc2f5d0d553882484855f9c7e4ce7a02cc835

Contents?: true

Size: 868 Bytes

Versions: 58

Compression:

Stored size: 868 Bytes

Contents

module Pulitzer
  class Tag < ActiveRecord::Base
    has_many :post_tags, as: :label, dependent: :destroy
    has_many :versions, through: :post_tags
    has_many :posts, through: :versions

    has_many :active_versions, -> { active }, through: :post_tags, source: :version
    has_many :active_posts, through: :active_versions, source: :post

    has_many :children, class_name: 'Pulitzer::Tag', dependent: :destroy, foreign_key: :parent_id
    belongs_to :parent, class_name: 'Pulitzer::Tag', touch: true

    validates :name, presence: true, uniqueness: true

    scope :hierarchical, -> { where hierarchical: true  }
    scope :flat,  -> { where hierarchical: false }
    scope :root,  -> { hierarchical.where(parent_id: nil) }

    def self.named(name = "")
      find_by name: name
    end

    def root?
      hierarchical? && parent_id.nil?
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
pulitzer-0.15.12 app/models/pulitzer/tag.rb
pulitzer-0.15.11 app/models/pulitzer/tag.rb
pulitzer-0.15.10 app/models/pulitzer/tag.rb
pulitzer-0.15.9 app/models/pulitzer/tag.rb
pulitzer-0.15.8 app/models/pulitzer/tag.rb
pulitzer-0.15.7 app/models/pulitzer/tag.rb
pulitzer-0.15.6 app/models/pulitzer/tag.rb
pulitzer-0.15.5 app/models/pulitzer/tag.rb
pulitzer-0.15.4 app/models/pulitzer/tag.rb
pulitzer-0.15.3 app/models/pulitzer/tag.rb
pulitzer-0.15.2 app/models/pulitzer/tag.rb
pulitzer-0.15.1 app/models/pulitzer/tag.rb
pulitzer-0.15.0 app/models/pulitzer/tag.rb
pulitzer-0.14.4 app/models/pulitzer/tag.rb
pulitzer-0.14.3 app/models/pulitzer/tag.rb
pulitzer-0.14.2 app/models/pulitzer/tag.rb
pulitzer-0.14.1 app/models/pulitzer/tag.rb
pulitzer-0.14.0 app/models/pulitzer/tag.rb
pulitzer-0.13.1 app/models/pulitzer/tag.rb
pulitzer-0.12.5 app/models/pulitzer/tag.rb