roshi 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/roshi/active_model/validations/zip_code_validator.rb +16 -1
- data/lib/roshi/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b5c09922befe3b47f64bbb52bde87bca661fa84
|
4
|
+
data.tar.gz: 99c3480912980df3e04b0a36549a85416b229e3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7dfb63e670d812cd9ec61878d10bd9a44901c46c4ca063114f9f9a7c8d69631bd8113eb9dce97d958330b823d0599849b3d858656ba3b93007b70940b1cc583
|
7
|
+
data.tar.gz: 40368d0fc16e686d8cebeb24763dcf52e8c34e988f22b8490487b0cdaa1ac2f386bedc6e983139a169b3ec67723c130d808617639fac76340d4a8c7956d27cef
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
|
|
26
26
|
```ruby
|
27
27
|
class TestModel
|
28
28
|
validates :email, email: true
|
29
|
-
validates :zip_code, zip_code: true
|
29
|
+
validates :zip_code, zip_code: true # zip_code: { hiphenation: true }
|
30
30
|
validates :version_number, version_number: true
|
31
31
|
end
|
32
32
|
```
|
@@ -1,8 +1,23 @@
|
|
1
1
|
module ActiveModel
|
2
2
|
module Validations
|
3
3
|
class ZipCodeValidator < EachValidator
|
4
|
+
REGEXES = {
|
5
|
+
default: /\A\d{3}\-?\d{4}\z/i,
|
6
|
+
with_hiphenation: /\A\d{3}\-\d{4}\z/i,
|
7
|
+
without_hiphenation: /\A\d{7}\z/i
|
8
|
+
}
|
9
|
+
|
4
10
|
def validate_each(record, attribute, value)
|
5
|
-
|
11
|
+
regexp = case
|
12
|
+
when options[:hiphenation].nil?
|
13
|
+
REGEXES[:default]
|
14
|
+
when options[:hiphenation]
|
15
|
+
REGEXES[:with_hiphenation]
|
16
|
+
when options[:hiphenation] == false
|
17
|
+
REGEXES[:without_hiphenation]
|
18
|
+
end
|
19
|
+
|
20
|
+
unless value =~ regexp
|
6
21
|
record.errors.add(attribute, options[:message] || I18n.t('errors.messages.invalid'))
|
7
22
|
end
|
8
23
|
end
|
data/lib/roshi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roshi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kawahiro311
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.5.0
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: ActiveModel/ActiveRecord Validation Collection
|