Sha256: d360f804ea2986fb73befc294bb74267b4401e6b6b81b06a72b6b710bfc033f3

Contents?: true

Size: 399 Bytes

Versions: 6

Compression:

Stored size: 399 Bytes

Contents

class ExcludeSelfValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    recipients = record.send(attribute)
    
    if recipients.include?(record.sender)
      record.errors.add :recipients, (options[:message] || t('activerecord.errors.models.carrier/message.attributes.recipients.cannot_write_to_self') )
      recipients.delete(record.sender) 
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
carrier-0.1.5 app/validators/recipients/exclude_self.rb
carrier-0.1.4 app/validators/recipients/exclude_self.rb
carrier-0.1.3 app/validators/recipients/exclude_self.rb
carrier-0.1.2 app/validators/recipients/exclude_self.rb
carrier-0.1.1 app/validators/recipients/exclude_self.rb
carrier-0.1.0 app/validators/recipients/exclude_self.rb