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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89c1e7b7039c5e2ed89afcdc0f77456810045450
4
- data.tar.gz: 3c35070c49f8282a08f142ceb43bd7b03d833f44
3
+ metadata.gz: 5b5c09922befe3b47f64bbb52bde87bca661fa84
4
+ data.tar.gz: 99c3480912980df3e04b0a36549a85416b229e3e
5
5
  SHA512:
6
- metadata.gz: a147b67ee8260f0e806fb3ea096ccc6b077625136cc6f7b7a84618dd198456c5b1b480ba9cac6a75af82ffa10776b426150ad00db46bcc7efdd8bb7d5b7eaba6
7
- data.tar.gz: e88ad951639b8eb8062720614d8069eb25ab7977e4b44699be352b3606509a6dec898328da73bfe0c97a8f929bc3cf3bd5725b75d80d00760e87f4447e928cd1
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
- unless value =~ /\A\d{3}\-?\d{4}\z/i
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
@@ -1,3 +1,3 @@
1
1
  module Roshi
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
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.0
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-06 00:00:00.000000000 Z
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.4.5.1
121
+ rubygems_version: 2.5.0
122
122
  signing_key:
123
123
  specification_version: 4
124
124
  summary: ActiveModel/ActiveRecord Validation Collection