Sha256: 5fddac8ddad61ad19f88b0f34b724d4dd4f00979f7e96641bfb850929503ec2c
Contents?: true
Size: 1.62 KB
Versions: 1
Compression:
Stored size: 1.62 KB
Contents
# # Sends a single email, or a campaign. # class Ish::EmailContext include Mongoid::Document include Mongoid::Timestamps field :title def slug title end PAGE_PARAM_NAME = 'email_contexts_page' FROM_EMAILS = %w| piousbox@gmail.com victor@piousbox.com victor@wasya.co no-reply@piousbox.com | field :from_email validates_presence_of :from_email def self.from_email_list [ [nil, nil] ] + FROM_EMAILS.map { |i| [i, i] } end TYPE_SINGLE = 'TYPE_SINGLE' TYPE_CAMPAIGN = 'TYPE_CAMPAIGN' field :type, default: TYPE_SINGLE def self.types_list [ [TYPE_SINGLE, TYPE_SINGLE], [TYPE_CAMPAIGN, TYPE_CAMPAIGN] ] end field :subject validates_presence_of :subject field :body # validates_presence_of :body ## With plain type, there is no body but there are variables for templating. belongs_to :email_template field :rendered_str field :sent_at, type: DateTime field :scheduled_at, type: DateTime def self.all_campaigns Ish::EmailContext.where( type: TYPE_CAMPAIGN ) end def campaign_leads if self.type == TYPE_CAMPAIGN return ::EmailCampaignLead.where( email_campaign_id: self.id.to_s ).includes( :lead ) end end def leads campaign_leads&.map { |p| p.lead } end ## ## For templating: ## ## commonly: name, companyName field :tmpl, type: Hash, default: {} def body_templated out = email_template.body tmpl.each do |k, v| out.gsub!("{#{k}}", v) end out end field :to_email validates_presence_of :to_email, if: -> { type == TYPE_SINGLE } # # For tracking # attr_reader :tid end EmailCampaign = Ish::EmailContext
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ish_models-0.0.33.186 | lib/ish/email_context.rb |