ip_address_validator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'localized_each_validator', '>= 1.0.1'
4
+
5
+ group :development do
6
+ gem 'jeweler'
7
+ gem 'yard'
8
+ gem 'RedCloth', require: 'redcloth'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ RedCloth (4.2.3)
5
+ activemodel (3.0.3)
6
+ activesupport (= 3.0.3)
7
+ builder (~> 2.1.2)
8
+ i18n (~> 0.4)
9
+ activerecord (3.0.3)
10
+ activemodel (= 3.0.3)
11
+ activesupport (= 3.0.3)
12
+ arel (~> 2.0.2)
13
+ tzinfo (~> 0.3.23)
14
+ activesupport (3.0.3)
15
+ arel (2.0.3)
16
+ builder (2.1.2)
17
+ git (1.2.5)
18
+ i18n (0.4.2)
19
+ jeweler (1.5.1)
20
+ bundler (~> 1.0.0)
21
+ git (>= 1.2.5)
22
+ rake
23
+ localized_each_validator (1.0.1)
24
+ activerecord (>= 3.0)
25
+ activesupport (>= 3.0)
26
+ rake (0.8.7)
27
+ tzinfo (0.3.23)
28
+ yard (0.6.2)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ RedCloth
35
+ jeweler
36
+ localized_each_validator (>= 1.0.1)
37
+ yard
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Tim Morgan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,40 @@
1
+ h1. ip_address_validator -- Simple IP validator for Rails 3
2
+
3
+ | *Author* | Tim Morgan |
4
+ | *Version* | 1.0 (Oct 30, 2010) |
5
+ | *License* | Released under the MIT license. |
6
+
7
+ h2. About
8
+
9
+ This gem adds a very simple IP address format validator to be used with
10
+ ActiveRecord models in Rails 3.0. It supports localized error messages.
11
+
12
+ h2. Installation
13
+
14
+ Add the gem to your project's @Gemfile@:
15
+
16
+ <pre><code>
17
+ gem 'ip_address_validator'
18
+ </code></pre>
19
+
20
+ h2. Usage
21
+
22
+ This gem is an @EachValidator@, and thus is used with the @validates@ method:
23
+
24
+ <pre><code>
25
+ class User < ActiveRecord::Base
26
+ validates :last_login_ip,
27
+ ip_address: true
28
+ end
29
+ </code></pre>
30
+
31
+ The localization key is @invalid_ip@, and can be specified in the localized
32
+ YAML file like so:
33
+
34
+ <pre><code>
35
+ en:
36
+ activerecord:
37
+ errors:
38
+ messages:
39
+ invalid_ip: IP address is invalid.
40
+ </code></pre>
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = "ip_address_validator"
15
+ gem.summary = %Q{Simple IP address validation in Rails 3}
16
+ gem.description = %Q{A simple, localizable EachValidator for IPv4 and IPv6 address fields in ActiveRecord 3.0.}
17
+ gem.email = "git@timothymorgan.info"
18
+ gem.homepage = "http://github.com/riscfuture/ip_address_validator"
19
+ gem.authors = [ "Tim Morgan" ]
20
+ end
21
+ Jeweler::RubygemsDotOrgTasks.new
22
+
23
+ require 'yard'
24
+ YARD::Rake::YardocTask.new('doc') do |doc|
25
+ doc.options << "-m" << "textile"
26
+ doc.options << "--protected"
27
+ doc.options << "-r" << "README.textile"
28
+ doc.options << "-o" << "doc"
29
+ doc.options << "--title" << "ip_address_validator Documentation".inspect
30
+
31
+ doc.files = [ 'lib/*.rb', 'README.textile' ]
32
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ip_address_validator}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tim Morgan"]
12
+ s.date = %q{2010-12-30}
13
+ s.description = %q{A simple, localizable EachValidator for IPv4 and IPv6 address fields in ActiveRecord 3.0.}
14
+ s.email = %q{git@timothymorgan.info}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.textile",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/ip_address_validator.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/riscfuture/ip_address_validator}
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.7}
32
+ s.summary = %q{Simple IP address validation in Rails 3}
33
+
34
+ if s.respond_to? :specification_version then
35
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
+ s.specification_version = 3
37
+
38
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
+ s.add_runtime_dependency(%q<localized_each_validator>, [">= 1.0.1"])
40
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
41
+ s.add_development_dependency(%q<yard>, [">= 0"])
42
+ s.add_development_dependency(%q<RedCloth>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<localized_each_validator>, [">= 1.0.1"])
45
+ s.add_dependency(%q<jeweler>, [">= 0"])
46
+ s.add_dependency(%q<yard>, [">= 0"])
47
+ s.add_dependency(%q<RedCloth>, [">= 0"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<localized_each_validator>, [">= 1.0.1"])
51
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
+ s.add_dependency(%q<yard>, [">= 0"])
53
+ s.add_dependency(%q<RedCloth>, [">= 0"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,32 @@
1
+ require 'localized_each_validator'
2
+
3
+ # Validates IPv4 and IPv6 addresses. Uses the @invalid_ip@ error message key.
4
+ #
5
+ # @example
6
+ # validates :last_login_ip, ip_address: true
7
+ #
8
+ # h2. Options
9
+ #
10
+ # | @:ipv4_only@ | If @true@, IPv6 addresses are considered invalid. |
11
+ # | @:ipv6_only@ | If @true@, IPv4 addresses are considered invalid. |
12
+ # | @:message@ | A custom message to use if the IP is invalid. |
13
+ # | @:allow_nil@ | If true, @nil@ values are allowed. |
14
+
15
+ class IpAddressValidator < LocalizedEachValidator
16
+ error_key :invalid_ip
17
+
18
+ # @private
19
+ def valid?(_, _, value)
20
+ ip = nil
21
+ begin
22
+ ip = IPAddr.new(value)
23
+ rescue ArgumentError
24
+ return false
25
+ end
26
+
27
+ return false if ip.ipv4? and options[:ipv6_only]
28
+ return false if ip.ipv6? and options[:ipv4_only]
29
+
30
+ return true
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ip_address_validator
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Tim Morgan
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-30 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: localized_each_validator
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 0
30
+ - 1
31
+ version: 1.0.1
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: jeweler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: yard
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: RedCloth
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: *id004
74
+ description: A simple, localizable EachValidator for IPv4 and IPv6 address fields in ActiveRecord 3.0.
75
+ email: git@timothymorgan.info
76
+ executables: []
77
+
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - LICENSE
82
+ - README.textile
83
+ files:
84
+ - .document
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE
88
+ - README.textile
89
+ - Rakefile
90
+ - VERSION
91
+ - ip_address_validator.gemspec
92
+ - lib/ip_address_validator.rb
93
+ has_rdoc: true
94
+ homepage: http://github.com/riscfuture/ip_address_validator
95
+ licenses: []
96
+
97
+ post_install_message:
98
+ rdoc_options: []
99
+
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 1922130186424659959
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.3.7
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Simple IP address validation in Rails 3
126
+ test_files: []
127
+