Sha256: e25dfbf5c7a830eebead7f1fbcc770e50581d351160928154be32ff0daf06e22

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

class Wco::Lead
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  store_in collection: 'wco_leads'

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

  field :name
  field :phone
  field :address

  belongs_to :leadset, class_name: 'Wco::Leadset'
  has_one :photo,      class_name: 'Wco::Photo'

  has_and_belongs_to_many :conversations,           class_name: '::WcoEmail::Conversation'
  def convs; conversations; end
  has_many                :email_contexts,          class_name: '::WcoEmail::Context'
  def ctxs; email_contexts; end
  has_many                :email_actions,           class_name: '::WcoEmail::EmailAction'
  # has_and_belongs_to_many :scheduled_email_actions, class_name: '::WcoEmail::ScheduledEmailAction'
  def schs; email_actions; end
  has_and_belongs_to_many :email_campaigns,         class_name: '::WcoEmail::Campaign'
  has_and_belongs_to_many :tags,                    class_name: '::Wco::Tag'

  # has_many :galleries, class_name: 'Wco::Gallery'
  # has_many :videos, class_name: 'Wco::Video'

  def self.list
    all.map { |p| [ p.id, p.email ] }
  end

  OP_DELETE = 'delete'
  OP_ADD_TO_CAMPAIGN = 'add_to_campaign'
  OPS = [ OP_DELETE, OP_ADD_TO_CAMPAIGN ]

  has_many :unsubscribes, class_name: '::WcoEmail::Unsubscribe'
  field :unsubscribe_token
  def unsubscribe_token
    if !self[:unsubscribe_token]
      update_attributes({ unsubscribe_token: (0...8).map { (65 + rand(26)).chr }.join })
    end
    self[:unsubscribe_token]
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wco_models-3.1.0.45 app/models/wco/lead.rb
wco_models-3.1.0.44 app/models/wco/lead.rb
wco_models-3.1.0.43 app/models/wco/lead.rb
wco_models-3.1.0.42 app/models/wco/lead.rb
wco_models-3.1.0.41 app/models/wco/lead.rb
wco_models-3.1.0.40 app/models/wco/lead.rb
wco_models-3.1.0.39 app/models/wco/lead.rb
wco_models-3.1.0.38 app/models/wco/lead.rb