This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
*.gem | ||
*.rbc | ||
/.config | ||
/coverage/ | ||
/InstalledFiles | ||
/pkg/ | ||
/spec/reports/ | ||
/test/tmp/ | ||
/test/version_tmp/ | ||
/tmp/ | ||
|
||
## Specific to RubyMotion: | ||
.dat* | ||
.repl_history | ||
build/ | ||
|
||
## Documentation cache and generated files: | ||
/.yardoc/ | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
## Environment normalisation: | ||
/.bundle/ | ||
/lib/bundler/man/ | ||
|
||
# for a library or gem, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
Gemfile.lock | ||
.ruby-version | ||
.ruby-gemset | ||
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in activemodel-ipaddr_validator.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# activemodel-ipaddr_validator | ||
|
||
## Usage | ||
|
||
Add to your Gemfile: | ||
|
||
```rb | ||
gem 'activemodel-ipaddr_validator' | ||
``` | ||
|
||
Run: | ||
|
||
``` | ||
bundle install | ||
``` | ||
|
||
Then add the following to your model: | ||
|
||
```rb | ||
validates :my_ipaddr_attribute, ipaddr: true | ||
``` | ||
|
||
### Custom options | ||
|
||
Name | Value | Default | Description | ||
--------|---------|---------|------------------------------------- | ||
`ipv4` | Boolean | true | Accept IPv4. | ||
`ipv6` | Boolean | false | Accept IPv6. | ||
`array` | Boolean | false | Expect an array of strings. | ||
|
||
```rb | ||
validates :ipv6s_attribute, ipaddr: { array: true, ipv4: false, ipv6: true } | ||
serialize :ipv6s_attribute, Array | ||
``` | ||
|
||
## Validation outside a model | ||
|
||
If you need to validate a IP outside a model, you can do that: | ||
|
||
```rb | ||
IpaddrValidator.valid?(value, options) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'bundler/gem_tasks' | ||
require 'rspec/core/rake_task' | ||
|
||
RSpec::Core::RakeTask.new('spec') | ||
task default: :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
file = File.open(File.expand_path('../lib/ipaddr_validator/version.rb', __FILE__)) | ||
version = file.read.scan(/\d+\.\d+\.\d+/).first | ||
file.close | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'activemodel-ipaddr_validator' | ||
spec.version = version | ||
spec.authors = ['Yuku Takahashi'] | ||
spec.email = ['yuku@qiita.com'] | ||
spec.summary = 'A IPv4 and IPv6 validator for Rails 3 and 4.' | ||
spec.homepage = 'https://github.com/increments/activemodel-ipaddr_validator' | ||
spec.license = 'MIT' | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_dependency 'activemodel' | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.7' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_development_dependency 'rspec' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'ipaddr_validator/version' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class IpaddrValidator | ||
VERSION = '0.0.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
RSpec.configure do |config| | ||
config.color = true | ||
config.run_all_when_everything_filtered = true | ||
end |