active_validation 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -6
- data/.rspec +3 -3
- data/CODE_OF_CONDUCT.md +13 -0
- data/LICENSE.txt +17 -18
- data/README.md +100 -145
- data/active_validation.gemspec +4 -3
- data/bin/console +14 -0
- data/bin/rake +16 -0
- data/bin/setup +7 -0
- data/config/locales/en.yml +7 -8
- data/lib/active_validation.rb +4 -4
- data/lib/active_validation/matchers/{ensure_valid_latitude_format_of.rb → ensure_valid_coordinate_format_of.rb} +5 -5
- data/lib/active_validation/validators/coordinate_validator.rb +38 -0
- data/lib/active_validation/version.rb +1 -1
- metadata +11 -63
- data/lib/active_validation/matchers/ensure_valid_longitude_format_of.rb +0 -26
- data/lib/active_validation/validators/latitude_validator.rb +0 -9
- data/lib/active_validation/validators/longitude_validator.rb +0 -9
- data/spec/lib/alpha_numeric_validator_spec.rb +0 -91
- data/spec/lib/alpha_validator_spec.rb +0 -182
- data/spec/lib/base64_validator_spec.rb +0 -33
- data/spec/lib/boolean_validator_spec.rb +0 -35
- data/spec/lib/credit_card_validator_spec.rb +0 -686
- data/spec/lib/currency_validator_spec.rb +0 -63
- data/spec/lib/cusip_validator_spec.rb +0 -27
- data/spec/lib/email_validator_spec.rb +0 -109
- data/spec/lib/equality_validator_spec.rb +0 -334
- data/spec/lib/hex_validator_spec.rb +0 -73
- data/spec/lib/imei_validator_spec.rb +0 -41
- data/spec/lib/ip_validator_spec.rb +0 -33
- data/spec/lib/isbn_validator_spec.rb +0 -41
- data/spec/lib/isin_validator_spec.rb +0 -35
- data/spec/lib/latitude_validator_spec.rb +0 -31
- data/spec/lib/longitude_validator_spec.rb +0 -31
- data/spec/lib/mac_address_validator_spec.rb +0 -54
- data/spec/lib/name_validator_spec.rb +0 -39
- data/spec/lib/password_validator_spec.rb +0 -85
- data/spec/lib/phone_validator_spec.rb +0 -42
- data/spec/lib/sedol_validator_spec.rb +0 -31
- data/spec/lib/slug_validator_spec.rb +0 -41
- data/spec/lib/ssn_validator_spec.rb +0 -36
- data/spec/lib/url_validator_spec.rb +0 -106
- data/spec/lib/username_validator_spec.rb +0 -37
- data/spec/lib/uuid_validator_spec.rb +0 -157
- data/spec/spec_helper.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5ccff82b8b3a8db274c0bbc81e53cd8bb8d13b8
|
4
|
+
data.tar.gz: dad2de52f03c0c04804e5c9f38c4628223edce97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 671b0fd59813c7fee27ef9c77a54beeba2e828162b06a94666eecd54f7f4036e31f820aef3ee59031e4c35ea6db2dd174b1596cf22f35084e49179060e8fc78d
|
7
|
+
data.tar.gz: 28b97dc6717a429579c7d24a4e50e461001eabf94abf9418f074171cf294509a23a145294e07563ec99a1c3790579d2bb5b23db22592e291f2bb72b5fb0cceab
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2015 Juan Gomez
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -6,8 +6,6 @@
|
|
6
6
|
|
7
7
|
ActiveValidation is a collection of custom validators that are often required in Rails applications plus shoulda-style RSpec matchers to test the validation rules.
|
8
8
|
|
9
|
-
Currently supported validators: alpha, alpha-numeric, Base64, boolean, credit card, currency, CUSIP, email, equality, GTIN, hex, IMEI, IP, ISBN, ISIN, latitude, longitude, MAC address, name, password, phone, SEDOL, slug, SSN, url, username, and UUID.
|
10
|
-
|
11
9
|
Highly recommended validators:
|
12
10
|
* **DateTime:** Validates Timeliness - https://github.com/adzap/validates_timeliness
|
13
11
|
* **Existence:** Validates Existence - https://github.com/perfectline/validates_existence
|
@@ -28,9 +26,35 @@ Or install it yourself as:
|
|
28
26
|
|
29
27
|
$ gem install active_validation
|
30
28
|
|
31
|
-
##
|
32
|
-
|
33
|
-
|
29
|
+
## Table of Contents
|
30
|
+
|
31
|
+
* [Alpha](#alphavalidator)
|
32
|
+
* [AlphaNumeric](#alphanumericvalidator)
|
33
|
+
* [Base64](#base64validator)
|
34
|
+
* [Boolean](#booleanvalidator)
|
35
|
+
* [Coordinates](#coordinatesvalidator)
|
36
|
+
* [Credit Card](#creditcardvalidator)
|
37
|
+
* [Currency](#currencyvalidator)
|
38
|
+
* [CUSIP](#cusipvalidator)
|
39
|
+
* [Email](#emailvalidator)
|
40
|
+
* [Equality](#equalityvalidator)
|
41
|
+
* [Hex](#hexvalidator)
|
42
|
+
* [IMEI](#imeivalidator)
|
43
|
+
* [IP](#ipvalidator)
|
44
|
+
* [ISBN](#isbnvalidator)
|
45
|
+
* [ISIN](#isinvalidator)
|
46
|
+
* [MAC Address](#macaddressvalidator)
|
47
|
+
* [Name](#namevalidator)
|
48
|
+
* [Password](#passwordvalidator)
|
49
|
+
* [Phone](#phonevalidator)
|
50
|
+
* [SEDOL](#sedolvalidator)
|
51
|
+
* [Slug](#slugvalidator)
|
52
|
+
* [SSN](#ssnvalidator)
|
53
|
+
* [URL](#urlvalidator)
|
54
|
+
* [Username](#usernamevalidator)
|
55
|
+
* [UUID](#uuidvalidator)
|
56
|
+
|
57
|
+
## AlphaValidator
|
34
58
|
|
35
59
|
**Ex:** Example or Example Title
|
36
60
|
|
@@ -74,7 +98,7 @@ describe Book do
|
|
74
98
|
end
|
75
99
|
```
|
76
100
|
|
77
|
-
|
101
|
+
## AlphaNumericValidator
|
78
102
|
|
79
103
|
**Ex:** Example1 or Example Title 1
|
80
104
|
|
@@ -117,7 +141,7 @@ describe Book do
|
|
117
141
|
end
|
118
142
|
```
|
119
143
|
|
120
|
-
|
144
|
+
## Base64Validator
|
121
145
|
|
122
146
|
**Ex:** YW55IGNhcm5hbCBwbGVhcw==
|
123
147
|
|
@@ -152,7 +176,7 @@ describe Code do
|
|
152
176
|
end
|
153
177
|
```
|
154
178
|
|
155
|
-
|
179
|
+
## BooleanValidator
|
156
180
|
|
157
181
|
**Ex:** true or false or 1 or 0
|
158
182
|
|
@@ -188,7 +212,55 @@ describe User do
|
|
188
212
|
end
|
189
213
|
```
|
190
214
|
|
191
|
-
|
215
|
+
## CoordinateValidator
|
216
|
+
|
217
|
+
**Ex:** 178.213 or -34.985
|
218
|
+
|
219
|
+
**Rules:**
|
220
|
+
* Range: latitude (90 to -90), longitude (180 to -180)
|
221
|
+
* Characters: 0-9
|
222
|
+
|
223
|
+
With an ActiveRecord model:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
# :coor => [78.47, -169.92]
|
227
|
+
# :lat => 91.23
|
228
|
+
# :lon => 123.85
|
229
|
+
|
230
|
+
class Location < ActiveRecord::Base
|
231
|
+
attr_accessor :coor, :lat, :lon, :name
|
232
|
+
validates :coor, coordinate: true
|
233
|
+
validates :lat, coordinate: { boundary: :latitude }
|
234
|
+
validates :lon, coordinate: { boundary: :longitude }
|
235
|
+
end
|
236
|
+
```
|
237
|
+
|
238
|
+
Or any ruby class:
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
# :coor => [78.47, -169.92]
|
242
|
+
# :lat => 91.23
|
243
|
+
# :lon => 123.85
|
244
|
+
|
245
|
+
class Location
|
246
|
+
include ActiveModel::Validations
|
247
|
+
attr_accessor :coor, :lat, :lon, :name
|
248
|
+
validates :coor, coordinate: true
|
249
|
+
validates :lat, coordinate: { boundary: :latitude }
|
250
|
+
validates :lon, coordinate: { boundary: :longitude }
|
251
|
+
end
|
252
|
+
```
|
253
|
+
|
254
|
+
RSpec matcher is also available for your convenience:
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
describe Location do
|
258
|
+
it { should ensure_valid_coordinate_format_of(:coor) }
|
259
|
+
it { should_not ensure_valid_coordinate_format_of(:name) }
|
260
|
+
end
|
261
|
+
```
|
262
|
+
|
263
|
+
## CreditCardValidator
|
192
264
|
|
193
265
|
**Ex:** 370000000000002
|
194
266
|
|
@@ -234,7 +306,7 @@ describe Invoice do
|
|
234
306
|
end
|
235
307
|
```
|
236
308
|
|
237
|
-
|
309
|
+
## CurrencyValidator
|
238
310
|
|
239
311
|
**Ex:** 123.00 or .1
|
240
312
|
|
@@ -278,7 +350,7 @@ describe Product do
|
|
278
350
|
end
|
279
351
|
```
|
280
352
|
|
281
|
-
|
353
|
+
## CusipValidator
|
282
354
|
|
283
355
|
**Ex:** 125509BG3
|
284
356
|
|
@@ -314,7 +386,7 @@ describe Bank do
|
|
314
386
|
end
|
315
387
|
```
|
316
388
|
|
317
|
-
|
389
|
+
## EmailValidator
|
318
390
|
|
319
391
|
**Ex:** user@example.com or user+123@example-site.com
|
320
392
|
|
@@ -360,7 +432,7 @@ describe User do
|
|
360
432
|
end
|
361
433
|
```
|
362
434
|
|
363
|
-
|
435
|
+
## EqualityValidator
|
364
436
|
|
365
437
|
**Operators:**
|
366
438
|
* Less than: x < y
|
@@ -402,52 +474,7 @@ describe Auction do
|
|
402
474
|
end
|
403
475
|
```
|
404
476
|
|
405
|
-
|
406
|
-
|
407
|
-
**Ex:** 73513537 or 4 006381 33393 1
|
408
|
-
|
409
|
-
**Rules:**
|
410
|
-
* Length: 8, 12, 13, or 14
|
411
|
-
* Characters: 0-9
|
412
|
-
|
413
|
-
With an ActiveRecord model:
|
414
|
-
|
415
|
-
```ruby
|
416
|
-
class Trade < ActiveRecord::Base
|
417
|
-
attr_accessor :code, :name
|
418
|
-
validates :code, gtin: true
|
419
|
-
end
|
420
|
-
```
|
421
|
-
|
422
|
-
Or any ruby class:
|
423
|
-
|
424
|
-
```ruby
|
425
|
-
class Trade
|
426
|
-
include ActiveModel::Validations
|
427
|
-
attr_accessor :code, :name
|
428
|
-
validates :code, gtin: true
|
429
|
-
end
|
430
|
-
```
|
431
|
-
|
432
|
-
Options: :strict, format: [:ean_8, :gtin_8, :ucc_8, :gtin_12, :upc, :upc_a, :ean, :ean_13, :gtin_13, :ucc_13, :gtin_14, :ucc_14]
|
433
|
-
Strict: requires not including spaces
|
434
|
-
|
435
|
-
```ruby
|
436
|
-
validates :code, gtin: { format: :ean_8 }
|
437
|
-
validates :code, gtin: { strict: true }
|
438
|
-
validates :code, gtin: { format: :ucc_13, strict: true }
|
439
|
-
```
|
440
|
-
|
441
|
-
RSpec matcher is also available for your convenience:
|
442
|
-
|
443
|
-
```ruby
|
444
|
-
describe Trade do
|
445
|
-
it { should ensure_valid_gtin_format_of(:code) }
|
446
|
-
it { should_not ensure_valid_gtin_format_of(:name) }
|
447
|
-
end
|
448
|
-
```
|
449
|
-
|
450
|
-
### HexValidator
|
477
|
+
## HexValidator
|
451
478
|
|
452
479
|
**Ex:** #a9a9a9 or #999 or aaaaaa or AAA
|
453
480
|
|
@@ -484,7 +511,7 @@ describe Color do
|
|
484
511
|
end
|
485
512
|
```
|
486
513
|
|
487
|
-
|
514
|
+
## ImeiValidator
|
488
515
|
|
489
516
|
**Ex:** 356843052637512 or 35-6843052-637512 or 35.6843052.637512
|
490
517
|
|
@@ -520,7 +547,7 @@ describe User do
|
|
520
547
|
end
|
521
548
|
```
|
522
549
|
|
523
|
-
|
550
|
+
## IpValidator
|
524
551
|
|
525
552
|
**Ex:** 0.0.0.0 or 127.0.0.1 or 167.39.240.31
|
526
553
|
|
@@ -556,7 +583,7 @@ describe User do
|
|
556
583
|
end
|
557
584
|
```
|
558
585
|
|
559
|
-
|
586
|
+
## IsbnValidator
|
560
587
|
|
561
588
|
**Ex:** 9519854894 or 0-9722051-1-x or 978 159059 9938
|
562
589
|
|
@@ -592,7 +619,7 @@ describe User do
|
|
592
619
|
end
|
593
620
|
```
|
594
621
|
|
595
|
-
|
622
|
+
## IsinValidator
|
596
623
|
|
597
624
|
**Ex:** US0378331005 or AU0000XVGZA3
|
598
625
|
|
@@ -629,79 +656,7 @@ describe User do
|
|
629
656
|
end
|
630
657
|
```
|
631
658
|
|
632
|
-
|
633
|
-
|
634
|
-
**Ex:** 78.213 or -34.985
|
635
|
-
|
636
|
-
**Rules:**
|
637
|
-
* Range: 90 to -90
|
638
|
-
* Characters: 0-9
|
639
|
-
|
640
|
-
With an ActiveRecord model:
|
641
|
-
|
642
|
-
```ruby
|
643
|
-
class Location < ActiveRecord::Base
|
644
|
-
attr_accessor :lat, :name
|
645
|
-
validates :lat, latitude: true
|
646
|
-
end
|
647
|
-
```
|
648
|
-
|
649
|
-
Or any ruby class:
|
650
|
-
|
651
|
-
```ruby
|
652
|
-
class Location
|
653
|
-
include ActiveModel::Validations
|
654
|
-
attr_accessor :lat, :name
|
655
|
-
validates :lat, latitude: true
|
656
|
-
end
|
657
|
-
```
|
658
|
-
|
659
|
-
RSpec matcher is also available for your convenience:
|
660
|
-
|
661
|
-
```ruby
|
662
|
-
describe Location do
|
663
|
-
it { should ensure_valid_latitude_format_of(:lat) }
|
664
|
-
it { should_not ensure_valid_latitude_format_of(:name) }
|
665
|
-
end
|
666
|
-
```
|
667
|
-
|
668
|
-
### LongitudeValidator
|
669
|
-
|
670
|
-
**Ex:** 165.371 or -56.152
|
671
|
-
|
672
|
-
**Rules:**
|
673
|
-
* Range: 180 to -180
|
674
|
-
* Characters: 0-9
|
675
|
-
|
676
|
-
With an ActiveRecord model:
|
677
|
-
|
678
|
-
```ruby
|
679
|
-
class Location < ActiveRecord::Base
|
680
|
-
attr_accessor :lon, :name
|
681
|
-
validates :lon, longitude: true
|
682
|
-
end
|
683
|
-
```
|
684
|
-
|
685
|
-
Or any ruby class:
|
686
|
-
|
687
|
-
```ruby
|
688
|
-
class Location
|
689
|
-
include ActiveModel::Validations
|
690
|
-
attr_accessor :lon, :name
|
691
|
-
validates :lon, longitude: true
|
692
|
-
end
|
693
|
-
```
|
694
|
-
|
695
|
-
RSpec matcher is also available for your convenience:
|
696
|
-
|
697
|
-
```ruby
|
698
|
-
describe Location do
|
699
|
-
it { should ensure_valid_longitude_format_of(:lon) }
|
700
|
-
it { should_not ensure_valid_longitude_format_of(:name) }
|
701
|
-
end
|
702
|
-
```
|
703
|
-
|
704
|
-
### MacAddressValidator
|
659
|
+
## MacAddressValidator
|
705
660
|
|
706
661
|
**Ex:**
|
707
662
|
'08:00:2b:01:02:03'
|
@@ -742,7 +697,7 @@ describe Device do
|
|
742
697
|
end
|
743
698
|
```
|
744
699
|
|
745
|
-
|
700
|
+
## NameValidator
|
746
701
|
|
747
702
|
**Ex:** James Brown or Billy Bob Thorton Jr
|
748
703
|
|
@@ -779,7 +734,7 @@ describe User do
|
|
779
734
|
end
|
780
735
|
```
|
781
736
|
|
782
|
-
|
737
|
+
## PasswordValidator
|
783
738
|
|
784
739
|
**Ex:** password or password123 or pa!!word
|
785
740
|
|
@@ -821,7 +776,7 @@ describe User do
|
|
821
776
|
end
|
822
777
|
```
|
823
778
|
|
824
|
-
|
779
|
+
## PhoneValidator
|
825
780
|
|
826
781
|
**Ex:** 555 333 4444 or (555) 123-4567 or +1 (555) 123 4567 ext-890
|
827
782
|
|
@@ -856,7 +811,7 @@ describe User do
|
|
856
811
|
end
|
857
812
|
```
|
858
813
|
|
859
|
-
|
814
|
+
## SedolValidator
|
860
815
|
|
861
816
|
**Ex:** B0WNLY7
|
862
817
|
|
@@ -891,7 +846,7 @@ describe Trade do
|
|
891
846
|
end
|
892
847
|
```
|
893
848
|
|
894
|
-
|
849
|
+
## SlugValidator
|
895
850
|
|
896
851
|
**Ex:** slug1234 or slug-1234
|
897
852
|
|
@@ -926,7 +881,7 @@ describe User do
|
|
926
881
|
end
|
927
882
|
```
|
928
883
|
|
929
|
-
|
884
|
+
## SsnValidator
|
930
885
|
|
931
886
|
**Ex:** 333-22-4444 or 333224444
|
932
887
|
|
@@ -961,7 +916,7 @@ describe User do
|
|
961
916
|
end
|
962
917
|
```
|
963
918
|
|
964
|
-
|
919
|
+
## UrlValidator
|
965
920
|
|
966
921
|
**Ex:** example.com or http://www.example.com
|
967
922
|
|
@@ -1011,7 +966,7 @@ describe User do
|
|
1011
966
|
end
|
1012
967
|
```
|
1013
968
|
|
1014
|
-
|
969
|
+
## UsernameValidator
|
1015
970
|
|
1016
971
|
**Ex:** username123 or username
|
1017
972
|
|
@@ -1047,7 +1002,7 @@ describe User do
|
|
1047
1002
|
end
|
1048
1003
|
```
|
1049
1004
|
|
1050
|
-
|
1005
|
+
## UuidValidator
|
1051
1006
|
|
1052
1007
|
**Ex:** 886313e1-3b8a-5372-9b90-0c9aee199e5d
|
1053
1008
|
|