missing_validators 2.2.0 → 2.3.0
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 +4 -4
- data/.travis.yml +2 -4
- data/README.md +27 -0
- data/lib/locales/en.yml +7 -0
- data/lib/missing_validators.rb +3 -0
- data/lib/missing_validators/matchers/ensure_valid_ip_address_format_of.rb +20 -0
- data/lib/missing_validators/matchers/ensure_valid_latitude_format_of.rb +20 -0
- data/lib/missing_validators/matchers/ensure_valid_longitude_format_of.rb +20 -0
- data/lib/missing_validators/validators/ip_address_validator.rb +18 -0
- data/lib/missing_validators/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69f96be612b01b17548c8371081a07503a839d9d
|
4
|
+
data.tar.gz: 81aa7d4f38e293706346b6f8650277e5a1ecebbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7d665173e2507cb08903b469f6e3bde90237be1ae6a77237c4465eb8f25918ce996b55c1644a22aa71be92d239d1b5c12fea52b124dc81c5538247481263b13
|
7
|
+
data.tar.gz: 723c7275a5c93ca540e9617392bcc5238c0d8fb884129fa7ea55cdb230f020b2d01e89aa32a823d4d1415d11767c29148b56ef9bfa0bd3087004c1c9b39f8ea7
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -141,6 +141,33 @@ RSpec matcher is also available for your convenience:
|
|
141
141
|
it { should ensure_valid_mac_address_format_of }
|
142
142
|
end
|
143
143
|
|
144
|
+
### IpAddressValidator
|
145
|
+
|
146
|
+
Ensures that IP address is in the correct format:
|
147
|
+
|
148
|
+
'192.168.0.10'
|
149
|
+
|
150
|
+
With an ActiveRecord model:
|
151
|
+
|
152
|
+
class Host < ActiveRecord::Base
|
153
|
+
attr_accessor :ip
|
154
|
+
validates :ip, ip_address: true
|
155
|
+
end
|
156
|
+
|
157
|
+
Or any ruby class:
|
158
|
+
|
159
|
+
class Host
|
160
|
+
include ActiveModel::Validations
|
161
|
+
attr_accessor :ip
|
162
|
+
validates :ip, ip_address: true
|
163
|
+
end
|
164
|
+
|
165
|
+
RSpec matcher is also available for your convenience:
|
166
|
+
|
167
|
+
describe Host do
|
168
|
+
it { should ensure_valid_ip_address_format_of }
|
169
|
+
end
|
170
|
+
|
144
171
|
### ColorValidator
|
145
172
|
|
146
173
|
Ensures that the color is a hexadecimal value starting with '#':
|
data/lib/locales/en.yml
CHANGED
@@ -7,6 +7,7 @@ en:
|
|
7
7
|
email: "is not a valid email address"
|
8
8
|
url: "is not a valid URL"
|
9
9
|
mac_address: "is not a valid MAC address"
|
10
|
+
ip_address: "is not a valid IP address"
|
10
11
|
longitude: "is not a valid longitude"
|
11
12
|
latitude: "is not a valid latitude"
|
12
13
|
color: "is not a valid hexadecimal color"
|
@@ -21,3 +22,9 @@ en:
|
|
21
22
|
ensure_valid_mac_address_format_of:
|
22
23
|
failure_message_for_should: "#{model} should ensure valid MAC address format of attribute #{attr}"
|
23
24
|
failure_message_for_should_not: "#{model} should not ensure valid MAC address format of attribute #{attr}"
|
25
|
+
ensure_valid_latitude_format_of:
|
26
|
+
failure_message_for_should: "#{model} should ensure valid latitude format of attribute #{attr}"
|
27
|
+
failure_message_for_should_not: "#{model} should not ensure valid latitude format of attribute #{attr}"
|
28
|
+
ensure_valid_longitude_format_of:
|
29
|
+
failure_message_for_should: "#{model} should ensure valid longitude format of attribute #{attr}"
|
30
|
+
failure_message_for_should_not: "#{model} should not ensure valid longitude format of attribute #{attr}"
|
data/lib/missing_validators.rb
CHANGED
@@ -7,6 +7,7 @@ require 'missing_validators/validators/inequality_validator'
|
|
7
7
|
require 'missing_validators/validators/email_validator'
|
8
8
|
require 'missing_validators/validators/url_validator'
|
9
9
|
require 'missing_validators/validators/mac_address_validator'
|
10
|
+
require 'missing_validators/validators/ip_address_validator'
|
10
11
|
require 'missing_validators/validators/longitude_validator'
|
11
12
|
require 'missing_validators/validators/latitude_validator'
|
12
13
|
require 'missing_validators/validators/color_validator'
|
@@ -21,6 +22,8 @@ if defined?(RSpec)
|
|
21
22
|
require 'missing_validators/matchers/ensure_valid_url_format_of'
|
22
23
|
require 'missing_validators/matchers/ensure_valid_mac_address_format_of'
|
23
24
|
require 'missing_validators/matchers/ensure_valid_imei_format_of'
|
25
|
+
require 'missing_validators/matchers/ensure_valid_latitude_format_of'
|
26
|
+
require 'missing_validators/matchers/ensure_valid_longitude_format_of'
|
24
27
|
end
|
25
28
|
|
26
29
|
I18n.load_path << File.expand_path('../locales/en.yml', __FILE__)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
RSpec::Matchers.define :ensure_valid_ip_address_format_of do |attribute|
|
2
|
+
root = 'missing_validators.matchers.ensure_valid_ip_address_format_of'
|
3
|
+
|
4
|
+
match do |model|
|
5
|
+
model.send("#{attribute}=", 'invalid.ip.address')
|
6
|
+
model.valid?
|
7
|
+
|
8
|
+
if model.errors.to_hash.key?(attribute)
|
9
|
+
model.errors[attribute].include?(I18n.t('errors.messages.ip_address'))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
failure_message do |model|
|
14
|
+
I18n.t("#{root}.failure_message_for_should", model: model.class)
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_when_negated do |model|
|
18
|
+
I18n.t("#{root}.failure_message_for_should_not", model: model.class)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
RSpec::Matchers.define :ensure_valid_latitude_format_of do |attribute|
|
2
|
+
root = 'missing_validators.matchers.ensure_valid_latitude_format_of'
|
3
|
+
|
4
|
+
match do |model|
|
5
|
+
model.send("#{attribute}=", 90.01)
|
6
|
+
model.valid?
|
7
|
+
|
8
|
+
if model.errors.to_hash.key?(attribute)
|
9
|
+
model.errors[attribute].include?(I18n.t('errors.messages.latitude'))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
failure_message do |model|
|
14
|
+
I18n.t("#{root}.failure_message_for_should", model: model.class)
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_when_negated do |model|
|
18
|
+
I18n.t("#{root}.failure_message_for_should_not", model: model.class)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
RSpec::Matchers.define :ensure_valid_longitude_format_of do |attribute|
|
2
|
+
root = 'missing_validators.matchers.ensure_valid_longitude_format_of'
|
3
|
+
|
4
|
+
match do |model|
|
5
|
+
model.send("#{attribute}=", 180.01)
|
6
|
+
model.valid?
|
7
|
+
|
8
|
+
if model.errors.to_hash.key?(attribute)
|
9
|
+
model.errors[attribute].include?(I18n.t('errors.messages.longitude'))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
failure_message do |model|
|
14
|
+
I18n.t("#{root}.failure_message_for_should", model: model.class)
|
15
|
+
end
|
16
|
+
|
17
|
+
failure_message_when_negated do |model|
|
18
|
+
I18n.t("#{root}.failure_message_for_should_not", model: model.class)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Checks if the value of an attribute is a valid IP address.
|
2
|
+
#
|
3
|
+
# @example Validate that the device IP address is valid.
|
4
|
+
# class Host << ActiveRecord::Base
|
5
|
+
# attr_accessor :ip
|
6
|
+
# validates :ip, ip_address: true
|
7
|
+
# end
|
8
|
+
class IpAddressValidator < BaseValidator
|
9
|
+
private
|
10
|
+
|
11
|
+
IP_ADDRESS_FORMATS = [
|
12
|
+
/^(([0-9]|[0-9]{2}|1[0-9]{2}|2[0-5][0-9]|2[0-5][0-5])\.){3}([0-9]|[0-9]{2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/ # 192.168.0.10
|
13
|
+
]
|
14
|
+
|
15
|
+
def valid?(ip_address, _)
|
16
|
+
IP_ADDRESS_FORMATS.any? { |format| (ip_address =~ format).present? }
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: missing_validators
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Gridnev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -154,6 +154,9 @@ files:
|
|
154
154
|
- lib/missing_validators.rb
|
155
155
|
- lib/missing_validators/matchers/ensure_valid_email_format_of.rb
|
156
156
|
- lib/missing_validators/matchers/ensure_valid_imei_format_of.rb
|
157
|
+
- lib/missing_validators/matchers/ensure_valid_ip_address_format_of.rb
|
158
|
+
- lib/missing_validators/matchers/ensure_valid_latitude_format_of.rb
|
159
|
+
- lib/missing_validators/matchers/ensure_valid_longitude_format_of.rb
|
157
160
|
- lib/missing_validators/matchers/ensure_valid_mac_address_format_of.rb
|
158
161
|
- lib/missing_validators/matchers/ensure_valid_url_format_of.rb
|
159
162
|
- lib/missing_validators/validators/base_validator.rb
|
@@ -163,6 +166,7 @@ files:
|
|
163
166
|
- lib/missing_validators/validators/equality_validator.rb
|
164
167
|
- lib/missing_validators/validators/imei_validator.rb
|
165
168
|
- lib/missing_validators/validators/inequality_validator.rb
|
169
|
+
- lib/missing_validators/validators/ip_address_validator.rb
|
166
170
|
- lib/missing_validators/validators/latitude_validator.rb
|
167
171
|
- lib/missing_validators/validators/longitude_validator.rb
|
168
172
|
- lib/missing_validators/validators/mac_address_validator.rb
|
@@ -201,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
205
|
version: '0'
|
202
206
|
requirements: []
|
203
207
|
rubyforge_project:
|
204
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.5.1
|
205
209
|
signing_key:
|
206
210
|
specification_version: 4
|
207
211
|
summary: Adds some handy validators.
|