Sha256: 659d88aa8e9125153694c2e1a9bb7f6b678280c8d6bfac73ee4d203ed981aba4

Contents?: true

Size: 1.73 KB

Versions: 10

Compression:

Stored size: 1.73 KB

Contents

module C80OrderForm
  class MessageOrderValidator < ActiveModel::Validator
    def validate(record)
      unless record.errors.present?
        puts "<MessageOrderValidator.validate> record = #{record}"
        mark_please_used = false

        unless record.name.present?
          record.errors[:name] = 'Укажите, пожалуйста, Ваше имя'
          mark_please_used = true
        end

        if record.email_or_phone.present?
          # указан email
          if record.email_or_phone[/([a-z0-9_.-]+)@([a-z0-9-]+)\.[a-z.]+/].present?
          else
            # указан мобильный
            if record.email_or_phone[/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/].present?
            else
              if mark_please_used
                t2 = 'Номер телефона или email введены неверно'
              else
                t2 = 'Пожалуйста, укажите корректный номер телефона или email'
                mark_please_used = true
              end
              record.errors[:email_or_phone] = t2
            end
          end
        else
          if mark_please_used
            t1 = 'Укажите или номер телефона или email'
          else
            t1 = 'Укажите, пожалуйста, или номер телефона или email'
            mark_please_used = true
          end
          record.errors[:email_or_phone] = t1
        end

        unless record.comment.present?
          record.errors[:comment] = 'Сообщение не может быть пустым'
        end

        unless record.kapcha.blank?
          record.errors[:kapcha] = 'fail'
        end
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
c80_order_form-0.1.0.11 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.10 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.9 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.8 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.7 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.6 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.5 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.4 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.3 app/models/c80_order_form/message_order_validator.rb
c80_order_form-0.1.0.1 app/models/c80_order_form/message_order_validator.rb