validates_as_mobile 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/validates_as_mobile.rb +15 -8
- data/lib/validates_as_mobile/version.rb +1 -1
- metadata +1 -1
data/lib/validates_as_mobile.rb
CHANGED
@@ -2,17 +2,24 @@
|
|
2
2
|
require 'validates_as_mobile/version'
|
3
3
|
|
4
4
|
module ValidatesAsMobile
|
5
|
-
def validates_as_mobile(*args)
|
6
|
-
regexp_not_blank = /\A((8|\+7)[\s]?)\(?(9[0-3][0-9]|941|95[0-6]|958|96[0-8]|97[0-1]|98[0-5]|98[7-9]|99[2-7]|999)\)?[-.|\s ]?([0-9]{3})[-.|\s]?([0-9]{2})[-.|\s ]?([0-9]{2})\z/
|
7
|
-
regexp_with_blank = /\A(((8|\+7)[\s]?)\(?(9[0-3][0-9]|941|95[0-6]|958|96[0-8]|97[0-1]|98[0-5]|98[7-9]|99[2-7]|999)\)?[-.|\s ]?([0-9]{3})[-.|\s]?([0-9]{2})[-.|\s ]?([0-9]{2}))?\z/
|
8
5
|
|
9
|
-
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def validates_as_mobile(*args)
|
12
|
+
regexp_not_blank = /\A((8|\+7)[\s]?)\(?(9[0-3][0-9]|941|95[0-6]|958|96[0-8]|97[0-1]|98[0-5]|98[7-9]|99[2-7]|999)\)?[-.|\s ]?([0-9]{3})[-.|\s]?([0-9]{2})[-.|\s ]?([0-9]{2})\z/
|
13
|
+
regexp_with_blank = /\A(((8|\+7)[\s]?)\(?(9[0-3][0-9]|941|95[0-6]|958|96[0-8]|97[0-1]|98[0-5]|98[7-9]|99[2-7]|999)\)?[-.|\s ]?([0-9]{3})[-.|\s]?([0-9]{2})[-.|\s ]?([0-9]{2}))?\z/
|
14
|
+
|
15
|
+
configuration = { :message => 'Not Russian mobile phone format.', :with => regexp_not_blank, :allow_nil => false }
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
configuration.update(args.pop) if args.last.is_a?(Hash)
|
18
|
+
configuration[:with] = regexp_with_blank if configuration[:allow_nil]
|
13
19
|
|
14
|
-
|
20
|
+
validates args.first, :format => configuration
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
18
|
-
ActiveRecord::Base.
|
25
|
+
ActiveRecord::Base.send(:include, ValidatesAsMobile)
|