missing_validators 2.1.0 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20d6955d8cea6660f0661b86c0c8bacc1c151c51
4
- data.tar.gz: 23d7a1cb58094572414c1405852f2f9f4ec5f133
3
+ metadata.gz: 3f65865aefd5e694b3d66a992e5911db588495fc
4
+ data.tar.gz: 6b467746de2dfda53ca9ccfb436252239d8e2bc4
5
5
  SHA512:
6
- metadata.gz: 216d03e00fbce2b8ac39556ae4ce2d8ff825607966a1df3397193ad5753f15d129865647563837f228751ade2bae2196cee4109ba1b868bc1dc5a89191714c94
7
- data.tar.gz: 46100e5dc52c0e94675082ff9322b28195a417cd39fcf64b86a3783c500ef8cd6660853d46834b003b26946d85031bb22f137873d12136ecb6a879dfbb30f359
6
+ metadata.gz: 4b34f34eb414f0eb4caafff8fc9d9e1a60c1b2566a6ecd877586cabaf646dba2f61330edc0b1c2362071a0cf9f588e2495f7d8328a03794060585de782cd22b5
7
+ data.tar.gz: bd74c2184295194e278a2bc77a7ab1ca8742e2d6d9cc6e8adce656459ead378e51efe326c2894db311e091d89aa9de02aad77100897c621851531982c403f292
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Build Status](https://travis-ci.org/andrewgr/missing_validators.png)](https://travis-ci.org/andrewgr/missing_validators)
4
4
  [![Code Climate](https://codeclimate.com/github/andrewgr/missing_validators/badges/gpa.svg)](https://codeclimate.com/github/andrewgr/missing_validators)
5
5
  [![Test Coverage](https://codeclimate.com/github/andrewgr/missing_validators/badges/coverage.svg)](https://codeclimate.com/github/andrewgr/missing_validators/coverage)
6
+ [![Gem Version](https://badge.fury.io/rb/missing_validators.svg)](http://badge.fury.io/rb/missing_validators)
6
7
 
7
8
  MissingValidators is a collection of custom validators that are often required in Rails applications plus shoulda-style RSpec matchers to test the validation rules.
8
9
 
@@ -11,6 +11,9 @@ require 'missing_validators/validators/longitude_validator'
11
11
  require 'missing_validators/validators/latitude_validator'
12
12
  require 'missing_validators/validators/color_validator'
13
13
  require 'missing_validators/validators/imei_validator'
14
+ require 'missing_validators/validators/ein_validator'
15
+ require 'missing_validators/validators/ssn_validator'
16
+ require 'missing_validators/validators/zip_code_validator'
14
17
 
15
18
  if defined?(RSpec)
16
19
  require 'rspec/matchers'
@@ -0,0 +1,11 @@
1
+ class EinValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ record.errors.add(attribute, :invalid) unless valid_ein?(value)
4
+ end
5
+
6
+ private
7
+
8
+ def valid_ein?(value)
9
+ (value =~ /(\A\d{2}-\d{7}\Z)/).present?
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class SsnValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ record.errors.add(attribute, :invalid) if valid_ssn?(value)
4
+ end
5
+
6
+ private
7
+
8
+ def valid_ssn?(value)
9
+ (value =~ /(\A\d{3}-\d{2}-\d{4}\Z)/).nil?
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class ZipCodeValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ record.errors.add(attribute, :invalid) unless valid_zip_code?(value)
4
+ end
5
+
6
+ private
7
+
8
+ def valid_zip_code?(zip_code)
9
+ (zip_code =~ /(\A\d{5}\Z)|(\A\d{5}-\d{4}\Z)/).present?
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # Collection of custom validators that are often required in Rails apps.
2
2
  module MissingValidators
3
3
  # Gem version
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  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.1.0
4
+ version: 2.2.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: 2015-05-09 00:00:00.000000000 Z
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -158,6 +158,7 @@ files:
158
158
  - lib/missing_validators/matchers/ensure_valid_url_format_of.rb
159
159
  - lib/missing_validators/validators/base_validator.rb
160
160
  - lib/missing_validators/validators/color_validator.rb
161
+ - lib/missing_validators/validators/ein_validator.rb
161
162
  - lib/missing_validators/validators/email_validator.rb
162
163
  - lib/missing_validators/validators/equality_validator.rb
163
164
  - lib/missing_validators/validators/imei_validator.rb
@@ -165,7 +166,9 @@ files:
165
166
  - lib/missing_validators/validators/latitude_validator.rb
166
167
  - lib/missing_validators/validators/longitude_validator.rb
167
168
  - lib/missing_validators/validators/mac_address_validator.rb
169
+ - lib/missing_validators/validators/ssn_validator.rb
168
170
  - lib/missing_validators/validators/url_validator.rb
171
+ - lib/missing_validators/validators/zip_code_validator.rb
169
172
  - lib/missing_validators/version.rb
170
173
  - missing_validators.gemspec
171
174
  - spec/spec_helper.rb
@@ -198,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
201
  version: '0'
199
202
  requirements: []
200
203
  rubyforge_project:
201
- rubygems_version: 2.2.2
204
+ rubygems_version: 2.4.5.1
202
205
  signing_key:
203
206
  specification_version: 4
204
207
  summary: Adds some handy validators.