drexed-validators 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/validators/currency_validator.rb +4 -2
- data/app/validators/email_validator.rb +4 -2
- data/app/validators/hex_validator.rb +4 -2
- data/app/validators/html_validator.rb +4 -2
- data/app/validators/ip_validator.rb +4 -2
- data/app/validators/name_validator.rb +4 -2
- data/app/validators/password_validator.rb +4 -2
- data/app/validators/phone_validator.rb +7 -10
- data/app/validators/slug_validator.rb +4 -2
- data/app/validators/ssn_validator.rb +4 -2
- data/app/validators/url_validator.rb +4 -2
- data/app/validators/username_validator.rb +4 -2
- data/app/validators/zipcode_validator.rb +4 -2
- data/lib/drexed/validators/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4433d34c4246c278a52fd5b5ddb19821f6ca55df
|
4
|
+
data.tar.gz: f7d5e49fcf1ad6ab598a58a4ee278a7cb173a19f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
4
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2013-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|