Skip to content

Instantly share code, notes, and snippets.

@bjoerne2
Created July 14, 2017 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerne2/efd5894e3b492a53fa8eea77153f6b20 to your computer and use it in GitHub Desktop.
Save bjoerne2/efd5894e3b492a53fa8eea77153f6b20 to your computer and use it in GitHub Desktop.
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