Files
nairobi/app/models/local_census_record.rb
Javi Martín f07c422f21 Apply Layout/SpaceInLambdaLiteral rubocop rule
I had mixed feelings about this rule, since I like spaces where
possible.

However, I changed my mind when I realized writing `->(thing) { }` was
similar to defining a method, and we don't have a space before the
parenthesis when defining a method.
2019-10-26 13:03:49 +02:00

20 lines
600 B
Ruby

class LocalCensusRecord < ApplicationRecord
before_validation :sanitize
validates :document_number, presence: true
validates :document_type, presence: true
validates :date_of_birth, presence: true
validates :postal_code, presence: true
validates :document_number, uniqueness: { scope: :document_type }
scope :search, ->(terms) { where("document_number ILIKE ?", "%#{terms}%") }
private
def sanitize
self.document_type = self.document_type&.strip
self.document_number = self.document_number&.strip
self.postal_code = self.postal_code&.strip
end
end