validates_as_mobile 0.0.1 → 0.0.2

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.
@@ -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
- configuration = { :message => 'Not Russian mobile phone format.', :with => regexp_not_blank, :allow_nil => false }
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
- configuration.update(args.pop) if args.last.is_a?(Hash)
12
- configuration[:with] = regexp_with_blank if configuration[:allow_nil]
17
+ configuration.update(args.pop) if args.last.is_a?(Hash)
18
+ configuration[:with] = regexp_with_blank if configuration[:allow_nil]
13
19
 
14
- validates args.first, :format => configuration
20
+ validates args.first, :format => configuration
21
+ end
15
22
  end
16
23
  end
17
24
 
18
- ActiveRecord::Base.extend ValidateAsMobile
25
+ ActiveRecord::Base.send(:include, ValidatesAsMobile)
@@ -1,3 +1,3 @@
1
1
  module ValidatesAsMobile
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_as_mobile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: