Sha256: 5427182b4cf3c075f4fc09fad4e8378197d68d94aa9c8a1e3b802221343fe198

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

class Wco::Tag
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  store_in collection: 'wco_tags'

  field :slug
  validates :slug, presence: true, uniqueness: true
  index({ slug: -1 })

  belongs_to :parent, class_name: 'Wco::Tag', inverse_of: :sons
  has_many :sons, class_name: 'Wco::Tag', inverse_of: :parent

  has_many :email_filters, class_name: 'WcoEmail::EmailFilter', inverse_of: :tag

  has_and_belongs_to_many :conversations, class_name: 'WcoEmail::Conversation', index: true
  has_and_belongs_to_many :message_stubs, class_name: 'WcoEmail::MessageStub'
  has_and_belongs_to_many :headlines # ,     class_name: 'Headline'
  has_and_belongs_to_many :leads, index: true # ,         class_name: 'Lead'
  has_and_belongs_to_many :leadsets # ,      class_name: 'Leadset'
  has_and_belongs_to_many :galleries
  has_and_belongs_to_many :reports
  has_and_belongs_to_many :videos
  has_and_belongs_to_many :logs

  INBOX = 'inbox'
  def self.inbox
    find_or_create_by({ slug: INBOX })
  end

  TRASH = 'trash'
  def self.trash
    find_or_create_by({ slug: TRASH })
  end

  SPAM = 'spam'
  def self.spam
    find_or_create_by({ slug: SPAM })
  end

  def to_s
    slug
  end
  def self.list
    [[nil,nil]] + all.order_by( slug: :asc ).map { |p| [ p.slug, p.id ] }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wco_models-3.1.0.152 app/models/wco/tag.rb
wco_models-3.1.0.151 app/models/wco/tag.rb
wco_models-3.1.0.150 app/models/wco/tag.rb
wco_models-3.1.0.149 app/models/wco/tag.rb
wco_models-3.1.0.148 app/models/wco/tag.rb