Sha256: 176e032f3aa5a8b1244b25d366a1361413dee1eb44d3fb8441aee742c48c6a0b

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

##
## Send a single email
##

class ::Ish::EmailContext
  include Mongoid::Document
  include Mongoid::Timestamps

  field :slug
  validates_uniqueness_of :slug, allow_nil: true

  field :preview_str, type: :string
  def preview_str
    if self[:preview_str].presence
      return self[:preview_str]
    else
      return tmpl.preview_str
    end
  end

  field :body
  def body
    if self[:body].presence
      return self[:body]
    else
      return tmpl.body
    end
  end

  PAGE_PARAM_NAME = 'email_contexts_page'

  field :from_email
  # validates_presence_of :from_email

  field :subject
  # validates_presence_of :subject



  belongs_to :email_template
  def tmpl; email_template; end

  belongs_to :scheduled_email_action, class_name: '::Office::ScheduledEmailAction', optional: true
  def sch; scheduled_email_action; end

  field :rendered_str

  field :sent_at, type: DateTime
  field :send_at, type: DateTime


  def self.unsent; new.unsent; end
  def unsent; Ish::EmailContext.where( sent_at: nil ); end

  def self.scheduled; new.scheduled; end
  def scheduled
    # or({ :send_at.lte => Time.now }, { :send_at => nil }) ## This won't work b/c I need draft state!
    Ish::EmailContext.where({ :send_at.lte => Time.now  })
  end

  def self.from_email_list
    Ish::EmailCampaign.from_email_list
  end

  field :lead_id, type: :integer
  def lead; Lead.find( lead_id ); end
  def to_email; lead[:email]; end ## @TODO: remove, just use the lead. _vp_ 2023-03-27


  ##
  ## For tracking / utm
  ##
  attr_reader :tid

  def get_binding
    @lead = lead()
    binding()
  end

end
Ctx = ::Ish::EmailContext

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ish_models-0.0.33.228 lib/ish/email_context.rb
ish_models-0.0.33.227 lib/ish/email_context.rb
ish_models-0.0.33.226 lib/ish/email_context.rb
ish_models-0.0.33.225 lib/ish/email_context.rb
ish_models-0.0.33.224 lib/ish/email_context.rb
ish_models-0.0.33.222 lib/ish/email_context.rb
ish_models-0.0.33.221 lib/ish/email_context.rb
ish_models-0.0.33.219 lib/ish/email_context.rb
ish_models-0.0.33.217 lib/ish/email_context.rb