From 3de5a0b51bc85d02ae9a07c9df66a1fbca61eace Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Mon, 4 Sep 2017 09:02:37 +0300 Subject: [PATCH] Fix code climate offences #569 --- app/models/contact/ident.rb | 12 ++++++------ lib/validators/e164_validator.rb | 12 +++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/models/contact/ident.rb b/app/models/contact/ident.rb index 5ca44c28d..5cd26f17b 100644 --- a/app/models/contact/ident.rb +++ b/app/models/contact/ident.rb @@ -7,7 +7,7 @@ class Contact::Ident validates :code, presence: true, code: true validates :code, iso8601: { date_only: true }, if: :birthday? - validates :type, presence: true, inclusion: { in: Proc.new { types } } + validates :type, presence: true, inclusion: { in: proc { types } } validates :country_code, presence: true, iso31661_alpha2: true validate :mismatched @@ -16,15 +16,15 @@ class Contact::Ident '2003' => [ [:code, :blank], [:type, :blank], - [:country_code, :blank], + [:country_code, :blank] ], '2005' => [ [:base, :mismatch], [:code, :invalid_national_id], [:code, :invalid_reg_no], [:code, :invalid_iso8601], - [:country_code, :invalid_iso31661_alpha2], - ], + [:country_code, :invalid_iso31661_alpha2] + ] } end @@ -36,7 +36,7 @@ class Contact::Ident def self.mismatches [ - Mismatch.new('birthday', Country.new('EE')), + Mismatch.new('birthday', Country.new('EE')) ] end @@ -63,7 +63,7 @@ class Contact::Ident private # https://github.com/rails/rails/issues/1513 - def validation_context=(value); end + def validation_context=(_value); end def mismatched mismatched = self.class.mismatches.include?(Mismatch.new(type, country)) diff --git a/lib/validators/e164_validator.rb b/lib/validators/e164_validator.rb index 8bde2112f..e5807e585 100644 --- a/lib/validators/e164_validator.rb +++ b/lib/validators/e164_validator.rb @@ -1,10 +1,12 @@ class E164Validator < ActiveModel::EachValidator def validate_each(record, attribute, _value) - validator = ActiveModel::Validations::LengthValidator.new(maximum: 17, attributes: attribute) - validator.validate(record) + length_validator = ActiveModel::Validations:: + LengthValidator.new(maximum: 17, attributes: attribute) + length_validator.validate(record) - validator = ActiveModel::Validations::FormatValidator.new(with: /\+[0-9]{1,3}\.[0-9]{1,14}?/, - attributes: attribute) - validator.validate(record) + format_validator = ActiveModel::Validations:: + FormatValidator.new(with: /\+[0-9]{1,3}\.[0-9]{1,14}?/, + attributes: attribute) + format_validator.validate(record) end end