phone_validator 1.0.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.
- data/README.md +37 -0
- data/lib/phone_validator.rb +16 -0
- metadata +130 -0
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Phone Validator
|
2
|
+
|
3
|
+
[](http://travis-ci.org/ZenCocoon/phone_validator)
|
4
|
+
|
5
|
+
[phone_validator](https://github.com/ZenCocoon/phone_validator) makes phone validation natural for ActiveModel 3+ objects.
|
6
|
+
The validation is using the excellent [global_phone](https://github.com/sstephenson/global_phone)
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
```
|
11
|
+
activemodel >= 3.0.0
|
12
|
+
global_phone >= 1.0.1
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Add to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'phone_validator'
|
21
|
+
```
|
22
|
+
|
23
|
+
Run:
|
24
|
+
|
25
|
+
```
|
26
|
+
bundle install
|
27
|
+
```
|
28
|
+
|
29
|
+
Then add the following to your model:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
validates :my_phone_attribute, :phone => true
|
33
|
+
```
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
MIT License. Copyright 2013 Sébastien Grosjean, sponsored by [BookingSync, Vacation Rental's Booking Calendar Software](http://www.bookingsync.com)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# PhoneValidator makes phone validation natural for ActiveModel object. Validation using global_phone.
|
2
|
+
class PhoneValidator < ActiveModel::EachValidator
|
3
|
+
@@default_options = {}
|
4
|
+
|
5
|
+
def self.default_options
|
6
|
+
@@default_options
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
options = @@default_options.merge(self.options)
|
11
|
+
|
12
|
+
unless GlobalPhone.validate(value)
|
13
|
+
record.errors.add(attribute, options[:message] || :invalid)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phone_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sebastien Grosjean
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activemodel
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: global_phone
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.1
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.9'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: guard-rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: appraisal
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.4'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0.4'
|
94
|
+
description: phone_validator makes phone validation natural for ActiveModel 3+ objects.
|
95
|
+
Validation using global_phone.
|
96
|
+
email: public@zencocoon.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files:
|
100
|
+
- README.md
|
101
|
+
files:
|
102
|
+
- lib/phone_validator.rb
|
103
|
+
- README.md
|
104
|
+
homepage: http://github.com/ZenCocoon/phone_validator
|
105
|
+
licenses: []
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.23
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: A phone validator for Rails 3+.
|
129
|
+
test_files: []
|
130
|
+
has_rdoc:
|