activemodel-ip_address_validator 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3dcac9e71de23f6ba53df67419d4cf6a6c81340f6cf6d754bc8b03f2dbe30145
4
+ data.tar.gz: 9b8167f0f3d5b9ffef1d63d012b4d541d6838392b241116f9de094844c36027f
5
+ SHA512:
6
+ metadata.gz: d2e2df84ea63d41be5ef7e46513e93431530ea39ca9e5db92317a5de0e681ebce276bc1769f46911b8c706a330bf6ba7a1d28373feb53caf2d272b7eeb256a1c
7
+ data.tar.gz: 803dd6fa13a87587637bd127a841d7669d476eb2c621c0437788f1bedc94bea02ce8e99d7b486d6990e2c19792d13084afc7e2294660ff4585b2e22e4727f2b9
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /gemfiles/*.gemfile.lock
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,28 @@
1
+ require: rubocop-performance
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+
6
+ Style/AsciiComments:
7
+ Enabled: false
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Style/RedundantSelf:
13
+ Enabled: false
14
+
15
+ Style/StringLiterals:
16
+ Enabled: true
17
+ EnforcedStyle: double_quotes
18
+
19
+ Layout/EndOfLine:
20
+ Enabled: true
21
+ EnforcedStyle: lf
22
+
23
+ Metrics/BlockLength:
24
+ Exclude:
25
+ - spec/**/*
26
+
27
+ Metrics/LineLength:
28
+ Max: 128
@@ -0,0 +1,12 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.6
7
+ - 2.5.5
8
+ - 2.6.3
9
+ gemfile:
10
+ - gemfiles/activemodel_5.0.gemfile
11
+ - gemfiles/activemodel_5.1.gemfile
12
+ - gemfiles/activemodel_5.2.gemfile
@@ -0,0 +1,6 @@
1
+ ## Unreleased
2
+
3
+
4
+ ## 0.1.0 (2019-06-19)
5
+
6
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in activemodel-ip_address_validator.gemspec
8
+ gemspec
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activemodel-ip_address_validator (0.1.0)
5
+ activemodel (>= 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.2.3)
11
+ activesupport (= 5.2.3)
12
+ activesupport (5.2.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ ast (2.4.0)
18
+ concurrent-ruby (1.1.5)
19
+ diff-lcs (1.3)
20
+ i18n (1.6.0)
21
+ concurrent-ruby (~> 1.0)
22
+ jaro_winkler (1.5.3)
23
+ minitest (5.11.3)
24
+ parallel (1.17.0)
25
+ parser (2.6.3.0)
26
+ ast (~> 2.4.0)
27
+ rainbow (3.0.0)
28
+ rake (12.3.2)
29
+ rspec (3.8.0)
30
+ rspec-core (~> 3.8.0)
31
+ rspec-expectations (~> 3.8.0)
32
+ rspec-mocks (~> 3.8.0)
33
+ rspec-core (3.8.1)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-expectations (3.8.4)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-mocks (3.8.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.8.0)
41
+ rspec-support (3.8.2)
42
+ rubocop (0.71.0)
43
+ jaro_winkler (~> 1.5.1)
44
+ parallel (~> 1.10)
45
+ parser (>= 2.6)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (>= 1.4.0, < 1.7)
49
+ rubocop-performance (1.3.0)
50
+ rubocop (>= 0.68.0)
51
+ ruby-progressbar (1.10.1)
52
+ thread_safe (0.3.6)
53
+ tzinfo (1.2.5)
54
+ thread_safe (~> 0.1)
55
+ unicode-display_width (1.6.0)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ activemodel-ip_address_validator!
62
+ bundler (~> 1.16)
63
+ rake (~> 12.0)
64
+ rspec (~> 3.8)
65
+ rubocop (>= 0.71.0)
66
+ rubocop-performance (>= 1.3.0)
67
+
68
+ BUNDLED WITH
69
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Yuji Hanamura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # ActiveModel::IpAddressValidator
2
+
3
+ ActiveModel validator for ip address.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/activemodel-ip_address_validator.svg)](https://badge.fury.io/rb/activemodel-ip_address_validator)
6
+ [![Build Status](https://travis-ci.org/yujideveloper/activemodel-ip_address_validator.svg?branch=master)](https://travis-ci.org/yujideveloper/activemodel-ip_address_validator)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/110218584f1f8621f6ae/maintainability)](https://codeclimate.com/github/yujideveloper/activemodel-ip_address_validator/maintainability)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'activemodel-ip_address_validator'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install activemodel-ip_address_validator
24
+
25
+ ## Usage
26
+
27
+ ``` ruby
28
+ validates :last_login_ip, ip_address: true
29
+ ```
30
+
31
+ Specify ip address version.
32
+ ``` ruby
33
+ validates :last_login_ip, ip_address: { version: :v4 }
34
+ ```
35
+
36
+ ### Options
37
+
38
+ | Name | Type | Description | Default |
39
+ |:-----|:-----|:------------|:--------|
40
+ | `version` | Symbol or Array of Symbol | Allowed ip address version. `:v4`, `:v6`, `%i[v4 v6]` | `%i[v4 v6]` |
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yujideveloper/activemodel-ip_address_validator.
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "activemodel/ip_address_validator/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "activemodel-ip_address_validator"
9
+ spec.version = ActiveModel::IpAddressValidator::VERSION
10
+ spec.authors = ["Yuji Hanamura"]
11
+ spec.email = ["yuji.developer@gmail.com"]
12
+
13
+ spec.summary = "ActiveModel validator for ip address."
14
+ spec.description = "ActiveModel validator for ip address."
15
+ spec.homepage = "https://github.com/yujideveloper/activemodel-ip_address_validator"
16
+ spec.license = "MIT"
17
+
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["changelog_uri"] = "https://github.com/yujideveloper/activemodel-ip_address_validator/tree/master/CHANGELOG.md"
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "activemodel", ">= 5.0"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 12.0"
35
+ spec.add_development_dependency "rspec", "~> 3.8"
36
+ spec.add_development_dependency "rubocop", ">= 0.71.0"
37
+ spec.add_development_dependency "rubocop-performance", ">= 1.3.0"
38
+ end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "activemodel/ip_address_validator"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gem "activemodel", "~> 5.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gem "activemodel", "~> 5.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org/"
4
+
5
+ gem "activemodel", "~> 5.2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "activemodel/ip_address_validator/version"
4
+
5
+ module ActiveModel
6
+ module IpAddressValidator
7
+ end
8
+ end
9
+
10
+ require "activemodel/validations/ip_address_validator"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveModel
4
+ module IpAddressValidator
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_model"
4
+ require "resolv"
5
+
6
+ module ActiveModel
7
+ module Validations
8
+ class IpAddressValidator < ::ActiveModel::EachValidator
9
+ PERMITTED_VERSION = %i[v4 v6].freeze
10
+
11
+ def initialize(options)
12
+ options[:version] ||= %i[v4 v6]
13
+ options[:version] = Array(options[:version])
14
+ super
15
+ end
16
+
17
+ def validate_each(record, attribute, value)
18
+ return if options[:version].include?(:v4) && ::Resolv::IPv4::Regex.match?(value)
19
+ return if options[:version].include?(:v6) && ::Resolv::IPv6::Regex.match?(value)
20
+
21
+ record_error(record, attribute, value)
22
+ end
23
+
24
+ def check_validity!
25
+ return if options[:version].present? && (options[:version] - PERMITTED_VERSION).blank?
26
+
27
+ raise ArgumentError, "Either :v4 and/or :v6 must be supplied."
28
+ end
29
+
30
+ private
31
+
32
+ def record_error(record, attribute, value)
33
+ record.errors.add(attribute, :invalid, options.except(:version).merge!(value: value))
34
+ end
35
+ end
36
+
37
+ module HelperMethods
38
+ def validates_ip_address_of(*attr_names)
39
+ validates_with IpAddressValidator, _merge_attributes(attr_names)
40
+ end
41
+ end
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activemodel-ip_address_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuji Hanamura
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.71.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.71.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.0
97
+ description: ActiveModel validator for ip address.
98
+ email:
99
+ - yuji.developer@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - activemodel-ip_address_validator.gemspec
115
+ - bin/console
116
+ - bin/setup
117
+ - gemfiles/activemodel_5.0.gemfile
118
+ - gemfiles/activemodel_5.1.gemfile
119
+ - gemfiles/activemodel_5.2.gemfile
120
+ - lib/activemodel/ip_address_validator.rb
121
+ - lib/activemodel/ip_address_validator/version.rb
122
+ - lib/activemodel/validations/ip_address_validator.rb
123
+ homepage: https://github.com/yujideveloper/activemodel-ip_address_validator
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ allowed_push_host: https://rubygems.org
128
+ homepage_uri: https://github.com/yujideveloper/activemodel-ip_address_validator
129
+ source_code_uri: https://github.com/yujideveloper/activemodel-ip_address_validator
130
+ changelog_uri: https://github.com/yujideveloper/activemodel-ip_address_validator/tree/master/CHANGELOG.md
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.7.6
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: ActiveModel validator for ip address.
151
+ test_files: []