missing_validators 0.7.0 → 0.7.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: 3a753662765a4f524c5b48aa7319306c92be6723
4
- data.tar.gz: 6728c6fcfeeb1e4e10fe55170de856997f146064
3
+ metadata.gz: 0159cef9b69c14ee7dd355533505e1155a3aa165
4
+ data.tar.gz: 22c6951ea90afc0a8241897dd5f32a118926beea
5
5
  SHA512:
6
- metadata.gz: f1bec22de6521794354b4e3eaba07352523045e948ad31525c69c4e638ca85e13273f3312d3ad56574b6c4bffdb4d30140ffcafd7dba0fe0c0736f756f1fa4a8
7
- data.tar.gz: c63f5eab4501058232e58300fc81e8fded0443289bba356018ef0affe597cc8b705f575062c84fd96a1446bf954e50228e576cb8881464c48386c7c311227574
6
+ metadata.gz: ed060b1d326b04e7e5d9e459c61b09dc3b13d5f5a47c4f91f05cfe4fe263f912011c34f44ea601a9290d30c790477aa72c56a59e879a5e40f976627093e5da91
7
+ data.tar.gz: 81742ca17ed623845bdee2b20c432a3cfe83a5569f50af1855bcf6b298884632639cf4dd7be86dc269c60b5e8e7639c2743b168104e0dc8fa39bb40abad3ae18
data/.rspec CHANGED
@@ -1,4 +1,4 @@
1
1
  --order random
2
2
  --colour
3
3
  --backtrace
4
- --format progress
4
+ --format progress
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
- gem 'rake'
4
+ gem 'rake'
data/LICENSE CHANGED
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -5,4 +5,4 @@ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new('spec')
7
7
 
8
- task :default => :spec
8
+ task :default => :spec
@@ -20,19 +20,20 @@ class EmailValidator < ActiveModel::EachValidator
20
20
  end
21
21
  end
22
22
 
23
- private
24
-
25
- def valid?(email, options)
26
- validate_format(email) \
27
- && validate_domain(email, Array.wrap(options[:domain]))
28
- end
29
-
30
- def validate_format(email)
23
+ def self.validate_format(email)
31
24
  !!(email =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i)
32
25
  end
33
26
 
34
- def validate_domain(email, domains)
27
+ def self.validate_domain(email, domains)
35
28
  email_downcased = email.to_s.downcase
36
29
  domains.empty? || domains.any? { |domain| email_downcased.end_with?(".#{domain.downcase}") }
37
30
  end
31
+
32
+ private
33
+
34
+ def valid?(email, options)
35
+ self.class.validate_format(email) \
36
+ && self.class.validate_domain(email, Array.wrap(options[:domain]))
37
+ end
38
+
38
39
  end
@@ -15,18 +15,12 @@ class MacAddressValidator < ActiveModel::EachValidator
15
15
  allow_blank = options[:allow_blank] || false
16
16
  return if allow_blank && value.blank?
17
17
 
18
- unless valid?(value, options)
18
+ unless self.class.valid?(value, options)
19
19
  record.errors[attribute] << (options[:message] || I18n.t('errors.messages.mac_address'))
20
20
  end
21
21
  end
22
22
 
23
- private
24
-
25
- def valid?(mac_address, options)
26
- validate_format(mac_address)
27
- end
28
-
29
- def validate_format(mac_address)
23
+ def self.validate_format(mac_address)
30
24
  !!(mac_address =~ /^([A-Fa-f0-9]{2}[:]){5}[A-Fa-f0-9]{2}?$/i) || # 08:00:2b:01:02:03
31
25
  !!(mac_address =~ /^([A-Fa-f0-9]{2}[-]){5}[A-Fa-f0-9]{2}?$/i) || # 08-00-2b-01-02-03
32
26
  !!(mac_address =~ /^([A-Fa-f0-9]{6}):[A-Fa-f0-9]{6}?$/i) || # 08002b:010203
@@ -34,4 +28,11 @@ class MacAddressValidator < ActiveModel::EachValidator
34
28
  !!(mac_address =~ /^([A-Fa-f0-9]{4}[\.]){2}[A-Fa-f0-9]{4}?$/i) || # 0800.2b01.0203
35
29
  !!(mac_address =~ /^[A-Fa-f0-9]{12}?$/i) # 08002b010203
36
30
  end
31
+
32
+ private
33
+
34
+ def self.valid?(mac_address, options)
35
+ validate_format(mac_address)
36
+ end
37
+
37
38
  end
@@ -19,29 +19,29 @@ class UrlValidator < ActiveModel::EachValidator
19
19
  record.errors[attribute] << (options[:message] || I18n.t('errors.messages.url'))
20
20
  end
21
21
 
22
- private
23
-
24
- DEFAULT_SCHEMES = [:http, :https]
25
-
26
- def valid?(uri, options)
27
- uri.kind_of?(URI::Generic) \
28
- && validate_domain(uri, Array.wrap(options[:domain])) \
29
- && validate_scheme(uri, Array.wrap(options[:scheme] || UrlValidator::DEFAULT_SCHEMES)) \
30
- && validate_root(uri, !!options[:root])
31
- end
32
-
33
- def validate_domain(uri, domains)
22
+ def self.validate_domain(uri, domains)
34
23
  host_downcased = uri.host.to_s.downcase
35
24
  domains.empty? || domains.any? { |domain| host_downcased.end_with?(".#{domain.downcase}") }
36
25
  end
37
26
 
38
- def validate_scheme(uri, schemes)
27
+ def self.validate_scheme(uri, schemes)
39
28
  scheme_downcased = uri.scheme.to_s.downcase
40
29
  schemes.empty? || schemes.any? { |scheme| scheme_downcased == scheme.to_s.downcase }
41
30
  end
42
31
 
43
- def validate_root(uri, should_validate)
44
- return true unless should_validate
32
+ def self.validate_root(uri)
45
33
  ['/', ''].include?(uri.path) && uri.query.blank? && uri.fragment.blank?
46
34
  end
35
+
36
+ private
37
+
38
+ DEFAULT_SCHEMES = [:http, :https]
39
+
40
+ def valid?(uri, options)
41
+ uri.kind_of?(URI::Generic) \
42
+ && self.class.validate_domain(uri, Array.wrap(options[:domain])) \
43
+ && self.class.validate_scheme(uri, Array.wrap(options[:scheme] || UrlValidator::DEFAULT_SCHEMES)) \
44
+ && (!!options[:root] ? self.class.validate_root(uri) : true)
45
+ end
46
+
47
47
  end
@@ -1,5 +1,5 @@
1
1
  # Provides a collection of custom validators that are often required in Rails applications.
2
2
  module MissingValidators
3
3
  # Gem version.
4
- VERSION = "0.7.0"
4
+ VERSION = "0.7.1"
5
5
  end
@@ -19,6 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.add_development_dependency 'rspec'
20
20
  gem.add_development_dependency 'shoulda-matchers'
21
21
 
22
- gem.add_dependency 'activemodel', '~> 3.0.0'
23
- gem.add_dependency 'activesupport', '~> 3.0.0'
22
+ gem.add_dependency 'activemodel', '> 3.0.0'
23
+ gem.add_dependency 'activesupport', '> 3.0.0'
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: missing_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Gridnev
@@ -42,28 +42,28 @@ dependencies:
42
42
  name: activemodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - '>'
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - '>'
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - '>'
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - '>'
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.0.0
69
69
  description: Validates email addresses, URLs, MAC addresses and inequality of attributes.