Sha256: ea0a4a213b18a6c9efd7d133f8aa5124ed43dc065e42029c995e3a9ee08cfdfe

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

class Spree::MailToCloud
  include ActiveModel::Validations
  include ActiveModel::Conversion
  attr_accessor :host, :subject, :sender_name, :sender_email, :recipient_name, :recipient_email, :message, :recipients, :invalid_recipients, :hide_recipients

  EMAILREGEX = /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,8}$/i

  validates :subject, :presence => true
  validates :sender_name, :presence => true
  validates :sender_email, :format => { :with => EMAILREGEX }
  validates :recipients, :length => {:minimum => 1, :message => "must contain at least one valid email address"}
  validates :invalid_recipients, :length => {:maximum => 0, :message => "must be removed"}

  def initialize(opts = {})
    @sender_email = opts[:sender_email] || ' '
    @sender_name  = opts[:sender_name]  || @sender_email.split('@', 2)[0].titleize
    @subject      = opts[:subject]      || I18n.t('email_to_friend.you_would_like_this', :sender_name => @sender_name, :site => Spree::Config[:site_url])

    @recipients = []
    @invalid_recipients = []

    @recipient_email = (opts[:recipient_email] || '').gsub(';', ',').gsub(/\s/ , '')
    @recipient_email.split(',').each do |address|
      if address =~ EMAILREGEX
         @recipients << address
      else
        @invalid_recipients << address
      end
    end

    @hide_recipients = opts[:hide_recipients] || false
    @message = opts[:message]
  end

  def persisted?
    false
  end

  def is_multi
    (@recipients.size + @invalid_recipients.size) > 1
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_multi_share-1.3.3 app/models/spree/mail_to_cloud.rb
spree_multi_share-1.3.2 app/models/spree/mail_to_cloud.rb