drexed-validators 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f314feca89c2256b04e440521356729b39b8053
4
- data.tar.gz: 32628191163fcce1e2b04d5cd35afca1bcc65f60
3
+ metadata.gz: 4433d34c4246c278a52fd5b5ddb19821f6ca55df
4
+ data.tar.gz: f7d5e49fcf1ad6ab598a58a4ee278a7cb173a19f
5
5
  SHA512:
6
- metadata.gz: aac895f1e0c55dde4f3f0c13e183b9b55963daad7013bd1be56118647c3c839d4f7dc224b10c7772e6a5075b6a062b09e3cc07d31ad15a2fb354848b583fe026
7
- data.tar.gz: fc44d8de5c8f8e77ba0ce670935d88442c34bf6aa8faa42f32a8558ed4b17f301a9e600083bf0dc1d23e6873ef27b74651e3fdff25fff7b3f53ca0f5aea481e7
6
+ metadata.gz: 8d45a0819809817eb325de9377d6a3e6448d36281f9350dc7fe1453eb4b5801d898815de83581b8025da8586b178039a4c3cafc84f5f56928e6f5df622131ed2
7
+ data.tar.gz: 5f328bd4c845eb544e4a2e9606376ef9324f79333a4aa2069c62d72a44605a74e1cd748d5365b21ee4d7884eba470e4619110fb939589ca9b3593795d08b78c8
@@ -1,7 +1,9 @@
1
1
  class CurrencyValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^\d*+(\.\d{1,2})?$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^\d*+(\.\d{1,2})?$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class EmailValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /\A[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/i
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /\A[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/i
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class HexValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class HtmlValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class IpValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class NameValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /\A([a-zA-Z'-]+\s+){0,4}[a-zA-Z'-]*\z/i
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /\A([a-zA-Z'-]+\s+){0,4}[a-zA-Z'-]*\z/i
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class PasswordValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^[a-z0-9_-]{6,18}$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^[a-z0-9_-]{6,18}$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,20 +1,17 @@
1
1
  class PhoneFormatValidator < ActiveModel::EachValidator
2
- def validate_each record, attribute, value
3
- region = options[:region] || :north_america
4
-
5
- formatted_value = value.gsub(/[\s\.\+\(\)-]*/, "")
6
- is_number = !(formatted_value =~ /^[-+]?[0-9]+$/).nil?
7
- unless is_number && validate_by_region(region, formatted_value)
8
- message = attribute.to_s.humanize + ' doesn\'t match an acceptable format.'
9
- record.errors[attribute] << (options[:message] || message )
2
+ def validate_each(record, attribute, value)
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ formatted_value = value.gsub(/[\s\.\+\(\)-]*/, "")
5
+ is_number = !(formatted_value =~ /^[-+]?[0-9]+$/).nil?
6
+ unless is_number && validate_by_region(options[:region], formatted_value)
7
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
8
+ end
10
9
  end
11
10
  end
12
11
 
13
12
  def validate_by_region(region, formatted_value)
14
13
  if region == :north_america
15
14
  valid_eleven_digit?(formatted_value) || valid_ten_digit?(formatted_value) || valid_seven_digit?(formatted_value)
16
- else
17
- false
18
15
  end
19
16
  end
20
17
 
@@ -1,7 +1,9 @@
1
1
  class SlugValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^[a-z0-9-]+$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^[a-z0-9-]+$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class UrlValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^\A([\d]{3}\-[\d]{2}\-[\d]{4}|[\d]{9})\Z$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^\A([\d]{3}\-[\d]{2}\-[\d]{4}|[\d]{9})\Z$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class UrlValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class UsernameValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^[a-z0-9_-]{3,16}$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^[a-z0-9_-]{3,16}$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  class ZipcodeValidator < ActiveModel::EachValidator
2
2
  def validate_each(object, attribute, value)
3
- unless value =~ /^\A[\d]{5}(?:[-|\s][\d]{4})?\Z$/
4
- object.errors[attribute] << (options[:message] || "is not formatted properly")
3
+ unless options[:allow_blank] || options[:allow_nil]
4
+ unless value =~ /^\A[\d]{5}(?:[-|\s][\d]{4})?\Z$/
5
+ object.errors[attribute] << (options[:message] || "is not formatted properly")
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,5 +1,5 @@
1
1
  module Drexed
2
2
  module Validators
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drexed-validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-05 00:00:00.000000000 Z
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler