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.
20 lines
600 B
Ruby
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
|