Sha256: d426862807193c68a1d561941940602f5473c3faa862338735d25a5920b853ca

Contents?: true

Size: 967 Bytes

Versions: 2

Compression:

Stored size: 967 Bytes

Contents

module BarkestCore
  ##
  # Defines the message generated by the generic contact form.
  class ContactMessage
    include ActiveModel::Model
    include ActiveModel::Validations
    include BarkestCore::EmailTester

    attr_accessor :your_name, :your_email, :related_to, :subject, :body, :remote_ip

    validates :your_name, presence: true
    validates :your_email, presence: true, format: { with: VALID_EMAIL_REGEX }
    validates :related_to, presence: true
    validates :subject, presence: true, if: :need_subject?
    validates :body, presence: true

    ##
    # Gets the full subject for the message.
    def full_subject
      return related_to if subject.blank?
      "#{related_to}: #{subject}"
    end

    ##
    # Sends the message.
    def send_message
      BarkestCore::ContactForm.contact(self).deliver_now
    end

    private

    def need_subject?
      related_to.to_s.downcase == 'other'
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
barkest_core-1.5.4.0 app/models/barkest_core/contact_message.rb
barkest_core-1.5.3.0 app/models/barkest_core/contact_message.rb