app/models/shoppe/customer.rb in shoppe-1.1.1 vs app/models/shoppe/customer.rb in shoppe-1.1.2
- old
+ new
@@ -1,20 +1,23 @@
module Shoppe
class Customer < ActiveRecord::Base
+ EMAIL_REGEX = /\A\b[A-Z0-9\.\_\%\-\+]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,6}\b\z/i
+ PHONE_REGEX = /\A[+?\d\ \-x\(\)]{7,}\z/
+
self.table_name = "shoppe_customers"
- has_many :addresses, :dependent => :restrict_with_exception, :class_name => "Shoppe::Address"
+ has_many :addresses, dependent: :restrict_with_exception, class_name: "Shoppe::Address"
- has_many :orders, :dependent => :restrict_with_exception, :class_name => "Shoppe::Order"
+ has_many :orders, dependent: :restrict_with_exception, class_name: "Shoppe::Order"
# Validations
- validates :email, :presence => true, :uniqueness => true, :format => {:with => /\A\b[A-Z0-9\.\_\%\-\+]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,6}\b\z/i}
- validates :phone, :presence => true, :format => {:with => /\A[\d\ \-x\(\)]{7,}\z/}
+ validates :email, presence: true, uniqueness: true, format: { with: EMAIL_REGEX}
+ validates :phone, presence: true, format: { with: PHONE_REGEX }
# All customers ordered by their ID desending
- scope :ordered, -> { order(:id => :desc)}
+ scope :ordered, -> { order(id: :desc)}
# The name of the customer in the format of "Company (First Last)" or if they don't have
# company specified, just "First Last".
#
# @return [String]
@@ -27,15 +30,15 @@
# @return [String]
def full_name
"#{first_name} #{last_name}"
end
- def self.ransackable_attributes(auth_object = nil)
+ def self.ransackable_attributes(auth_object = nil)
["id", "first_name", "last_name", "company", "email", "phone", "mobile"] + _ransackers.keys
end
-
+
def self.ransackable_associations(auth_object = nil)
[]
end
end
-end
\ No newline at end of file
+end