Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
Add metadata files
Browse files Browse the repository at this point in the history
  • Loading branch information
yuku committed Feb 6, 2015
1 parent f5a30d1 commit cfe417b
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
@@ -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
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in activemodel-ipaddr_validator.gemspec
gemspec
42 changes: 42 additions & 0 deletions README.md
@@ -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)
```
5 changes: 5 additions & 0 deletions Rakefile
@@ -0,0 +1,5 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new('spec')
task default: :spec
22 changes: 22 additions & 0 deletions activemodel-ipaddr_validator.gemspec
@@ -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
1 change: 1 addition & 0 deletions lib/activemodel-ipaddr_validator.rb
@@ -0,0 +1 @@
require 'ipaddr_validator/version'
3 changes: 3 additions & 0 deletions lib/ipaddr_validator/version.rb
@@ -0,0 +1,3 @@
class IpaddrValidator
VERSION = '0.0.0'
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,4 @@
RSpec.configure do |config|
config.color = true
config.run_all_when_everything_filtered = true
end

0 comments on commit cfe417b

Please sign in to comment.