Sha256: f9aff694587e3453c75ebf67b6092bb47c425e71de5fb2a2d6d34750784ab569

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module FormData
  class Customer < Base
    attribute :first_name,   String
    attribute :last_name,    String
    attribute :name,         String
    attribute :email,        String
    attribute :company_name, String
    attribute :country_code, String
    attribute :phone_code,   String
    attribute :phone_area,   String
    attribute :phone_number, String
    attribute :password,     String
    attribute :time_zone,    String
    attribute :device_uid,   String

    validates :time_zone, length: { maximum: 100 }, allow_blank: true
    validates :country_code, presence: true, length: { maximum: 3 }
    validate :valid_country_code?
    validates :first_name, presence: true, length: { maximum: 130 }
    validates :last_name, presence: true, length: { maximum: 130 }
    validates :email, presence: true, length: { maximum: 130 }, email: true
    validates :company_name, length: { maximum: 130 }, allow_blank: true

    validates :phone_code, presence: true, length: { minimum: 1, maximum: 10 }, numericality: true
    validates :phone_area, presence: true, length: { minimum: 1, maximum: 6 }, numericality: true
    validates :phone_number, presence: true, length: { minimum: 6, maximum: 12 }, numericality: true
    validates :password, presence: true, length: { minimum: 6, maximum: 128 }, confirmation: true

    protected

    def valid_country_code?
      errors.add(:country_code, :invalid) if ISO3166::Country.find_country_by_alpha3(country_code).nil?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/forms/form_data/customer.rb