validates_host 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/lib/validates_host.rb +10 -0
- data/lib/validates_host/domain_name_validator.rb +20 -0
- data/lib/validates_host/host_name_validator.rb +20 -0
- data/lib/validates_host/ip_validator.rb +20 -0
- data/lib/validates_host/remarkable.rb +3 -0
- data/lib/validates_host/remarkable/domain_name_matcher.rb +29 -0
- data/lib/validates_host/remarkable/host_name_matcher.rb +29 -0
- data/lib/validates_host/remarkable/ip_matcher.rb +29 -0
- data/lib/validates_host/shoulda-matchers.rb +3 -0
- data/lib/validates_host/shoulda-matchers/domain_name_matcher.rb +37 -0
- data/lib/validates_host/shoulda-matchers/host_name_matcher.rb +37 -0
- data/lib/validates_host/shoulda-matchers/ip_matcher.rb +37 -0
- data/lib/validates_host/version.rb +3 -0
- data/spec/fake_app/db/migrations/create_servers.rb +13 -0
- data/spec/fake_app/server.rb +5 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/validates_host.rb/domain_name_validator_spec.rb +38 -0
- data/spec/validates_host.rb/host_name_validator_spec.rb +38 -0
- data/spec/validates_host.rb/ip_validator_spec.rb +38 -0
- data/spec/validates_host.rb/remarkable/domain_name_matcher_spec.rb +20 -0
- data/spec/validates_host.rb/remarkable/host_name_matcher_spec.rb +20 -0
- data/spec/validates_host.rb/remarkable/ip_matcher_spec.rb +20 -0
- data/spec/validates_host.rb/shoulda-matchers/domain_name_matcher_spec.rb +20 -0
- data/spec/validates_host.rb/shoulda-matchers/host_name_matcher_spec.rb +20 -0
- data/spec/validates_host.rb/shoulda-matchers/ip_matcher_spec.rb +20 -0
- data/validates_host.gemspec +24 -0
- metadata +185 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Paulo Henrique Lopes Ribeiro
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# ValidatesHost
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'validates_host'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install validates_host
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "validates_host/version"
|
2
|
+
|
3
|
+
#ActiveModel Validators
|
4
|
+
require 'validates_host/host_name_validator'
|
5
|
+
require 'validates_host/domain_name_validator'
|
6
|
+
require 'validates_host/ip_validator'
|
7
|
+
|
8
|
+
#Rspec Matchers
|
9
|
+
require "validates_host/shoulda-matchers" if defined?(::Shoulda)
|
10
|
+
require "validates_host/remarkable" if defined?(::Remarkable)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class DomainNameValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
record.errors[attribute] << I18n.t("errors.messages.invalid") unless DomainName.new(value).valid?
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class DomainName
|
8
|
+
def initialize(domain_name)
|
9
|
+
@domain_name = domain_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
return true if @domain_name.nil?
|
14
|
+
@domain_name =~ /^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/
|
15
|
+
end
|
16
|
+
|
17
|
+
def domain_name
|
18
|
+
@domain_name
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class HostNameValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
record.errors[attribute] << I18n.t("errors.messages.invalid") unless HostName.new(value).valid?
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class HostName
|
8
|
+
def initialize(host_name)
|
9
|
+
@host_name = host_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
return true if @host_name.blank?
|
14
|
+
@host_name =~ /^[a-z][a-z0-9-]+$/
|
15
|
+
end
|
16
|
+
|
17
|
+
def host_name
|
18
|
+
@host_name
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class IpValidator < ActiveModel::EachValidator
|
2
|
+
def validate_each(record, attribute, value)
|
3
|
+
record.errors[attribute] << I18n.t("errors.messages.invalid") unless Ip.new(value).valid?
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Ip
|
8
|
+
def initialize(ip)
|
9
|
+
@ip = ip
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
return true if @ip.blank?
|
14
|
+
@ip =~ /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/
|
15
|
+
end
|
16
|
+
|
17
|
+
def ip
|
18
|
+
@ip
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'remarkable/active_model'
|
2
|
+
|
3
|
+
module Remarkable
|
4
|
+
module ActiveModel
|
5
|
+
module Matchers
|
6
|
+
class DomainNameMatcher < Remarkable::ActiveModel::Base
|
7
|
+
arguments :domain_name
|
8
|
+
|
9
|
+
collection_assertions :accept_valid_value?, :reject_valid_value?
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def accept_valid_value?
|
14
|
+
@subject.domain_name = 'example.com'
|
15
|
+
@subject.valid?.errors[:domain_name].should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
def reject_valid_value?
|
19
|
+
@subject.domain_name = 'example'
|
20
|
+
@subject.valid?.errors[:domain_name].should == ['is invalid']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def require_a_valid_domain_name(*args, &block)
|
25
|
+
DomainNameMatcher.new(*args, &block).spec(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'remarkable/active_model'
|
2
|
+
|
3
|
+
module Remarkable
|
4
|
+
module ActiveModel
|
5
|
+
module Matchers
|
6
|
+
class HostNameMatcher < Remarkable::ActiveModel::Base
|
7
|
+
arguments :host_name
|
8
|
+
|
9
|
+
collection_assertions :accept_valid_value?, :reject_valid_value?
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def accept_valid_value?
|
14
|
+
@subject.domain_name = 'bd01'
|
15
|
+
@subject.valid?.errors[:host_name].should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
def reject_valid_value?
|
19
|
+
@subject.domain_name = '01'
|
20
|
+
@subject.valid?.errors[:host_name].should == ['is invalid']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def require_a_valid_domain_name(*args, &block)
|
25
|
+
HostNameMatcher.new(*args, &block).spec(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'remarkable/active_model'
|
2
|
+
|
3
|
+
module Remarkable
|
4
|
+
module ActiveModel
|
5
|
+
module Matchers
|
6
|
+
class IpMatcher < Remarkable::ActiveModel::Base
|
7
|
+
arguments :ip
|
8
|
+
|
9
|
+
collection_assertions :accept_valid_value?, :reject_valid_value?
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def accept_valid_value?
|
14
|
+
@subject.domain_name = '10.10.10.1'
|
15
|
+
@subject.valid?.errors[:ip].should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
def reject_valid_value?
|
19
|
+
@subject.domain_name = '01'
|
20
|
+
@subject.valid?.errors[:ip].should == ['is invalid']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def require_a_valid_domain_name(*args, &block)
|
25
|
+
HostNameMatcher.new(*args, &block).spec(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "shoulda-matchers"
|
2
|
+
|
3
|
+
module Shoulda
|
4
|
+
module Matchers
|
5
|
+
module ActiveModel
|
6
|
+
def require_a_valid_domain_name(attribute = :domain_name)
|
7
|
+
DomainNameMatcher.new(attribute)
|
8
|
+
end
|
9
|
+
|
10
|
+
class DomainNameMatcher < ValidationMatcher
|
11
|
+
def initialize(attribute)
|
12
|
+
@attribute = attribute
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
"require #{@attribute} to be a valid domain name"
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches?(subject)
|
20
|
+
super(subject)
|
21
|
+
|
22
|
+
disallows_invalid_value and allows_valid_value
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def disallows_invalid_value
|
28
|
+
disallows_value_of("example")
|
29
|
+
end
|
30
|
+
|
31
|
+
def allows_valid_value
|
32
|
+
allows_value_of("example.com")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "shoulda-matchers"
|
2
|
+
|
3
|
+
module Shoulda
|
4
|
+
module Matchers
|
5
|
+
module ActiveModel
|
6
|
+
def require_a_valid_host_name(attribute = :host_name)
|
7
|
+
HostNameMatcher.new(attribute)
|
8
|
+
end
|
9
|
+
|
10
|
+
class HostNameMatcher < ValidationMatcher
|
11
|
+
def initialize(attribute)
|
12
|
+
@attribute = attribute
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
"require #{@attribute} to be a valid host name"
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches?(subject)
|
20
|
+
super(subject)
|
21
|
+
|
22
|
+
disallows_invalid_value and allows_valid_value
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def disallows_invalid_value
|
28
|
+
disallows_value_of("1bd")
|
29
|
+
end
|
30
|
+
|
31
|
+
def allows_valid_value
|
32
|
+
allows_value_of("bd01")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "shoulda-matchers"
|
2
|
+
|
3
|
+
module Shoulda
|
4
|
+
module Matchers
|
5
|
+
module ActiveModel
|
6
|
+
def require_a_valid_ip(attribute = :ip)
|
7
|
+
IpMatcher.new(attribute)
|
8
|
+
end
|
9
|
+
|
10
|
+
class IpMatcher < ValidationMatcher
|
11
|
+
def initialize(attribute)
|
12
|
+
@attribute = attribute
|
13
|
+
end
|
14
|
+
|
15
|
+
def description
|
16
|
+
"require #{@attribute} to be a valid ip"
|
17
|
+
end
|
18
|
+
|
19
|
+
def matches?(subject)
|
20
|
+
super(subject)
|
21
|
+
|
22
|
+
disallows_invalid_value and allows_valid_value
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def disallows_invalid_value
|
28
|
+
disallows_value_of("10.0.0")
|
29
|
+
end
|
30
|
+
|
31
|
+
def allows_valid_value
|
32
|
+
allows_value_of("10.10.10.1")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rspec"
|
3
|
+
require "active_record"
|
4
|
+
|
5
|
+
Dir.glob(File.dirname(__FILE__) + "/../lib/**/*.rb").each { |file| require file }
|
6
|
+
Dir.glob(File.dirname(__FILE__) + "/fake_app/**/*.rb").each { |file| require file }
|
7
|
+
|
8
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
9
|
+
|
10
|
+
CreateServers.migrate(:up)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DomainNameValidator do
|
4
|
+
context "when domain_name is invalid" do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new(:domain_name => "http://")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should set object as invalid" do
|
10
|
+
@server.valid?.should be_false
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set an error" do
|
14
|
+
@server.valid?
|
15
|
+
@server.errors[:domain_name].should == ['is invalid']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when domain_name is valid" do
|
20
|
+
before :each do
|
21
|
+
@server = Server.new(:domain_name => "example.com")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set object as valid" do
|
25
|
+
@server.valid?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not set an error on attribute" do
|
29
|
+
@server.valid?
|
30
|
+
@server.errors[:domain_name].should be_blank
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be valid with a nil value" do
|
35
|
+
@server = Server.new(:domain_name => nil)
|
36
|
+
@server.valid?.should be_true
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe HostNameValidator do
|
4
|
+
context "when host_name is invalid" do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new(:host_name => "http://")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should set object as invalid" do
|
10
|
+
@server.valid?.should be_false
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set an error" do
|
14
|
+
@server.valid?
|
15
|
+
@server.errors[:host_name].should == ['is invalid']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when host_name is valid" do
|
20
|
+
before :each do
|
21
|
+
@server = Server.new(:host_name => "bd01")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set object as valid" do
|
25
|
+
@server.valid?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not set an error on attribute" do
|
29
|
+
@server.valid?
|
30
|
+
@server.errors[:host_name].should be_blank
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be valid with a nil value" do
|
35
|
+
@server = Server.new(:host_name => nil)
|
36
|
+
@server.valid?.should be_true
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IpValidator do
|
4
|
+
context "when ip is invalid" do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new(:ip => "127.0.0")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should set object as invalid" do
|
10
|
+
@server.valid?.should be_false
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set an error" do
|
14
|
+
@server.valid?
|
15
|
+
@server.errors[:ip].should == ['is invalid']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when ip is valid" do
|
20
|
+
before :each do
|
21
|
+
@server = Server.new(:ip => "10.10.10.1")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set object as valid" do
|
25
|
+
@server.valid?.should be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not set an error on attribute" do
|
29
|
+
@server.valid?
|
30
|
+
@server.errors[:ip].should be_blank
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be valid with a nil value" do
|
35
|
+
@server = Server.new(:ip => nil)
|
36
|
+
@server.valid?.should be_true
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'remarkable/active_model'
|
3
|
+
|
4
|
+
describe Remarkable::ActiveModel::Matchers::DomainNameMatcher do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept on domain_name" do
|
10
|
+
@server.should require_a_valid_domain_name(:domain_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept without a specified attribute" do
|
14
|
+
@server.should require_a_valid_domain_name
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should reject on host_name" do
|
18
|
+
@server.should_not require_a_valid_domain_name(:host_name)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'remarkable/active_model'
|
3
|
+
|
4
|
+
describe Remarkable::ActiveModel::Matchers::HostNameMatcher do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept on host_name" do
|
10
|
+
@server.should require_a_valid_host_name(:host_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept without a specified attribute" do
|
14
|
+
@server.should require_a_valid_domain_name
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should reject on domain_name" do
|
18
|
+
@server.should_not require_a_valid_host_name(:domain_name)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'remarkable/active_model'
|
3
|
+
|
4
|
+
describe Remarkable::ActiveModel::Matchers::IpMatcher do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept on ip" do
|
10
|
+
@server.should require_a_valid_ip(:ip)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept without a specified attribute" do
|
14
|
+
@server.should require_a_valid_ip
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should reject on domain_name" do
|
18
|
+
@server.should_not require_a_valid_ip(:domain_name)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shoulda-matchers'
|
3
|
+
|
4
|
+
describe Shoulda::Matchers::ActiveModel::DomainNameMatcher do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept on domain_name" do
|
10
|
+
@server.should require_a_valid_domain_name(:domain_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept without a specified attribute" do
|
14
|
+
@server.should require_a_valid_domain_name
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should reject on host_name" do
|
18
|
+
@server.should_not require_a_valid_domain_name(:host_name)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shoulda-matchers'
|
3
|
+
|
4
|
+
describe Shoulda::Matchers::ActiveModel::HostNameMatcher do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept on host_name" do
|
10
|
+
@server.should require_a_valid_host_name(:host_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept without a specified attribute" do
|
14
|
+
@server.should require_a_valid_host_name
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should reject on domain_name" do
|
18
|
+
@server.should_not require_a_valid_host_name(:domain_name)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shoulda-matchers'
|
3
|
+
|
4
|
+
describe Shoulda::Matchers::ActiveModel::IpMatcher do
|
5
|
+
before :each do
|
6
|
+
@server = Server.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accept on ip" do
|
10
|
+
@server.should require_a_valid_ip(:ip)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept without a specified attribute" do
|
14
|
+
@server.should require_a_valid_ip
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should reject on domain_name" do
|
18
|
+
@server.should_not require_a_valid_ip(:domain_name)
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/validates_host/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Paulo Henrique Lopes Ribeiro"]
|
6
|
+
gem.email = %q{plribeiro3000@gmail.com}
|
7
|
+
gem.description = %q{Validates Host, Domain and IP}
|
8
|
+
gem.summary = %q{Host Validation Gem}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "validates_host"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ValidatesHost::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency("activerecord", ">= 3.0.0")
|
19
|
+
gem.add_development_dependency "rake"
|
20
|
+
gem.add_development_dependency "rspec", ">= 2.0.0"
|
21
|
+
gem.add_development_dependency "shoulda-matchers", ">= 1.0.0"
|
22
|
+
gem.add_development_dependency "remarkable_activerecord", "= 4.0.0.alpha4"
|
23
|
+
gem.add_development_dependency "sqlite3"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_host
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paulo Henrique Lopes Ribeiro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
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: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.0
|
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: 2.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: shoulda-matchers
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.0.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.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: remarkable_activerecord
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - '='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 4.0.0.alpha4
|
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: 4.0.0.alpha4
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: sqlite3
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Validates Host, Domain and IP
|
111
|
+
email: plribeiro3000@gmail.com
|
112
|
+
executables: []
|
113
|
+
extensions: []
|
114
|
+
extra_rdoc_files: []
|
115
|
+
files:
|
116
|
+
- .gitignore
|
117
|
+
- .rspec
|
118
|
+
- .rvmrc
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/validates_host.rb
|
124
|
+
- lib/validates_host/domain_name_validator.rb
|
125
|
+
- lib/validates_host/host_name_validator.rb
|
126
|
+
- lib/validates_host/ip_validator.rb
|
127
|
+
- lib/validates_host/remarkable.rb
|
128
|
+
- lib/validates_host/remarkable/domain_name_matcher.rb
|
129
|
+
- lib/validates_host/remarkable/host_name_matcher.rb
|
130
|
+
- lib/validates_host/remarkable/ip_matcher.rb
|
131
|
+
- lib/validates_host/shoulda-matchers.rb
|
132
|
+
- lib/validates_host/shoulda-matchers/domain_name_matcher.rb
|
133
|
+
- lib/validates_host/shoulda-matchers/host_name_matcher.rb
|
134
|
+
- lib/validates_host/shoulda-matchers/ip_matcher.rb
|
135
|
+
- lib/validates_host/version.rb
|
136
|
+
- spec/fake_app/db/migrations/create_servers.rb
|
137
|
+
- spec/fake_app/server.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
- spec/validates_host.rb/domain_name_validator_spec.rb
|
140
|
+
- spec/validates_host.rb/host_name_validator_spec.rb
|
141
|
+
- spec/validates_host.rb/ip_validator_spec.rb
|
142
|
+
- spec/validates_host.rb/remarkable/domain_name_matcher_spec.rb
|
143
|
+
- spec/validates_host.rb/remarkable/host_name_matcher_spec.rb
|
144
|
+
- spec/validates_host.rb/remarkable/ip_matcher_spec.rb
|
145
|
+
- spec/validates_host.rb/shoulda-matchers/domain_name_matcher_spec.rb
|
146
|
+
- spec/validates_host.rb/shoulda-matchers/host_name_matcher_spec.rb
|
147
|
+
- spec/validates_host.rb/shoulda-matchers/ip_matcher_spec.rb
|
148
|
+
- validates_host.gemspec
|
149
|
+
homepage: ''
|
150
|
+
licenses: []
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 1.8.24
|
170
|
+
signing_key:
|
171
|
+
specification_version: 3
|
172
|
+
summary: Host Validation Gem
|
173
|
+
test_files:
|
174
|
+
- spec/fake_app/db/migrations/create_servers.rb
|
175
|
+
- spec/fake_app/server.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- spec/validates_host.rb/domain_name_validator_spec.rb
|
178
|
+
- spec/validates_host.rb/host_name_validator_spec.rb
|
179
|
+
- spec/validates_host.rb/ip_validator_spec.rb
|
180
|
+
- spec/validates_host.rb/remarkable/domain_name_matcher_spec.rb
|
181
|
+
- spec/validates_host.rb/remarkable/host_name_matcher_spec.rb
|
182
|
+
- spec/validates_host.rb/remarkable/ip_matcher_spec.rb
|
183
|
+
- spec/validates_host.rb/shoulda-matchers/domain_name_matcher_spec.rb
|
184
|
+
- spec/validates_host.rb/shoulda-matchers/host_name_matcher_spec.rb
|
185
|
+
- spec/validates_host.rb/shoulda-matchers/ip_matcher_spec.rb
|