roshi 0.4.0 → 0.5.0
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 -0
- data/lib/roshi.rb +1 -1
- data/lib/roshi/active_model/validations/phone_number_validator.rb +26 -0
- data/lib/roshi/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 619ef8d2899a55d75de84d88ac85bbe7eb3f4ad3
|
4
|
+
data.tar.gz: 47ddfc446d64e0334ba3725da5347bd82b0485f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c9f1a79932a06bb913d26ff64892cc8f52e0bcb253b50269e5af03fb655f801fc3c3f57db85f2c5f95cd378a75395206e9d84c33edbfaf7aa92640379856a07
|
7
|
+
data.tar.gz: 2b985a3248e924e490585022bdfe32a574486789f208d5f2e3a469d799b82a369197f1e0936dde7a20b689aa726925678175c72b08835cf73adc4420195d4b13
|
data/README.md
CHANGED
@@ -27,6 +27,7 @@ Or install it yourself as:
|
|
27
27
|
class TestModel
|
28
28
|
validates :email, email: true
|
29
29
|
validates :zip_code, zip_code: true # zip_code: { hiphenation: true }
|
30
|
+
validates :phone_number, phone_number: true # phone_number: { hiphenation: true }
|
30
31
|
validates :hiragana, hiragana: true
|
31
32
|
validates :version_number, version_number: true
|
32
33
|
end
|
data/lib/roshi.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'active_model'
|
2
2
|
require 'roshi/version'
|
3
|
-
%w(email zip_code hiragana version_number).each do |validator_name|
|
3
|
+
%w(email zip_code phone_number hiragana version_number).each do |validator_name|
|
4
4
|
require "roshi/active_model/validations/#{validator_name}_validator"
|
5
5
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
class PhoneNumberValidator < EachValidator
|
4
|
+
REGEXES = {
|
5
|
+
default: /\A\d{2,4}\-?\d{2,4}\-?\d{4}\z/i,
|
6
|
+
with_hiphenation: /\A\d{2,4}\-\d{2,4}\-\d{4}\z/i,
|
7
|
+
without_hiphenation: /\A\d{6,12}\z/i
|
8
|
+
}
|
9
|
+
|
10
|
+
def validate_each(record, attribute, value)
|
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
|
21
|
+
record.errors.add(attribute, options[:message] || I18n.t('errors.messages.invalid'))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/roshi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roshi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kawahiro311
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/roshi.rb
|
99
99
|
- lib/roshi/active_model/validations/email_validator.rb
|
100
100
|
- lib/roshi/active_model/validations/hiragana_validator.rb
|
101
|
+
- lib/roshi/active_model/validations/phone_number_validator.rb
|
101
102
|
- lib/roshi/active_model/validations/version_number_validator.rb
|
102
103
|
- lib/roshi/active_model/validations/zip_code_validator.rb
|
103
104
|
- lib/roshi/version.rb
|