domain_validator 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 695d7e4c5fb856f0e57def793955382f6f1152e3
4
- data.tar.gz: 7617ccbbedc6a2d7b35c8af32df99b9ce8061074
3
+ metadata.gz: a951e441fa4015ac815c9ba5fee96609c22fc8a4
4
+ data.tar.gz: ae1724471b31badf6553fd783e5da8c5e905a17b
5
5
  SHA512:
6
- metadata.gz: 23ae0e6a4aaac595331de44150367dc6300757373e680cbda57565b08c6a85d8f47779b9b09cb5d1ffefa6d0bcb99d06643eb3e4df4628d62948bef2428b8588
7
- data.tar.gz: ad54f966aff37c5f933550abd42f5f38982a778930077ee054da6ab8dad0c59bb9c4f173951f600769b7576602a37e82bfc19f830cdbb5fc29175ac37af9462b
6
+ metadata.gz: a82193dea64c492105c0b64e847f02f8214f8b2a82a0c7048a1c29b4fe5501280ed60aea2d329e23898b875f1c93e1d5be84947d13176e5b1856ba563d61a502
7
+ data.tar.gz: 082544a780890525d87962ec301888a8842beb0d7696e6176ad26254142c0d34b1ecb1b08a66fc899b8d2e3085036c87f4c2f956d1f08411cf95d13c88104b13
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # DomainValidator
2
2
 
3
- ActiveModel vaidations for domains
4
-
5
3
  [![Build Status](https://travis-ci.org/kdayton-/domain_validator.png?branch=master)](https://travis-ci.org/kdayton-/domain_validator)
6
4
 
5
+ Adds a DomainValidator to ActiveModel, allowing for easy validation of FQDNs
6
+
7
+
7
8
  ## Installation
8
9
 
9
10
  Add this line to your application's Gemfile:
@@ -20,7 +21,7 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- Add a 'domain' validation to your ActiveModel enabled class
24
+ Add a domain validation to your ActiveModel enabled class
24
25
 
25
26
  ```ruby
26
27
  class User < ActiveRecord::Base
@@ -28,6 +29,16 @@ class User < ActiveRecord::Base
28
29
  end
29
30
  ```
30
31
 
32
+ ## Examples
33
+
34
+ ```ruby
35
+ user = User.new :domain => 'mydomain.com'
36
+ user.valid? # => true
37
+
38
+ user.domain = 'invalid*characters.com'
39
+ user.valid? # => false
40
+ ```
41
+
31
42
  ## Contributing
32
43
 
33
44
  1. Fork it
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["kyle@graphicflash.com"]
11
11
  spec.description = %q{Adds ActiveModel validation for domain format.}
12
12
  spec.summary = %q{Adds ActiveModel validation for domain format.}
13
- spec.homepage = ""
13
+ spec.homepage = "http://github.com/kdayton-/domain_validator"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "public_suffix"
22
21
  spec.add_dependency "activemodel"
23
22
 
24
23
  spec.add_development_dependency "bundler"
@@ -1,18 +1,18 @@
1
1
  require 'active_model'
2
2
  require 'active_model/validator'
3
3
 
4
- require 'public_suffix'
5
-
6
4
  module DomainValidator
7
5
  class Validator < ActiveModel::EachValidator
8
6
 
7
+ RE_DOMAIN = %r(^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)+$)
8
+
9
9
  def validate_each(record, attr_name, value)
10
10
  valid_domain = is_valid_domain?(value)
11
11
  record.errors.add(attr_name, options[:message] || "is invalid") and return unless valid_domain
12
12
  end
13
13
 
14
14
  def is_valid_domain?(domain)
15
- PublicSuffix.valid? domain
15
+ domain =~ RE_DOMAIN
16
16
  end
17
17
 
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module DomainValidator
2
- VERSION = [0, 0, 1].join "."
2
+ VERSION = [0, 0, 2].join "."
3
3
  end
@@ -71,7 +71,7 @@ describe DomainValidator do
71
71
 
72
72
  describe "error messages" do
73
73
  context "when the :message option is not defined" do
74
- subject { User.new :domain => "domain.withinvalidtld" }
74
+ subject { User.new :domain => "notadomain" }
75
75
  before { subject.valid? }
76
76
 
77
77
  it "should add the default message" do
@@ -80,7 +80,7 @@ describe DomainValidator do
80
80
  end
81
81
 
82
82
  context "when the :message option is defined" do
83
- subject { UserWithMessage.new :domain => "domain.withinvalidtld" }
83
+ subject { UserWithMessage.new :domain => "notadomain" }
84
84
  before { subject.valid? }
85
85
 
86
86
  it "should add the customized message" do
@@ -10,7 +10,7 @@ module DomainHelpers
10
10
  def invalid_domains
11
11
  [
12
12
  "notarealdomain",
13
- "domain.withinvalidtld"
13
+ "invalid*chars.com"
14
14
  ]
15
15
  end
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Dayton
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: public_suffix
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activemodel
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +86,7 @@ files:
100
86
  - spec/domain_validator_spec.rb
101
87
  - spec/spec_helper.rb
102
88
  - spec/support/domain_helpers.rb
103
- homepage: ''
89
+ homepage: http://github.com/kdayton-/domain_validator
104
90
  licenses:
105
91
  - MIT
106
92
  metadata: {}