Created
July 14, 2017 22:12
-
-
Save bjoerne2/efd5894e3b492a53fa8eea77153f6b20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConversationTransientModel | |
include ActiveModel::Validations | |
include ActiveModel::Validations::Callbacks | |
include ActiveModel::Conversion | |
extend ActiveModel::Naming | |
attr_accessor :recipients, :subject, :body | |
before_validation :clear_empty_recipients | |
validates :recipients, presence: true | |
validates :subject, presence: true | |
validates :body, presence: true | |
def initialize(attributes = {}) | |
attributes.each do |name, value| | |
send("#{name}=", value) | |
end | |
end | |
private | |
def clear_empty_recipients | |
recipients.select! { |recipient| !recipient.empty? } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment