activemodel-ipaddr_validator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be71e5c90ac86d95518c142d9243969badeca1bd
4
- data.tar.gz: b8e2b5727b7405ae66420a0c9db5d19c17b38823
3
+ metadata.gz: 037d801907b11ed64c3a96e80547ac4b656de833
4
+ data.tar.gz: ab0d5cdc1cbd57954d348438e6a955754e0750a2
5
5
  SHA512:
6
- metadata.gz: 7b29d674a86724069d6500a7538f51627df082444e62ffc69fb921cfe7737a284bfc702bb570c87ca499b6d495c0bcd6980b56300de579ffa61d09392f32063b
7
- data.tar.gz: 0fca558ff8310aff7dd62a9ec395ad10b4d1775f672f3a87bb8b91b9bd2cb4568c3073d4a967014806eaefa2713e9072d95db082ede5092f9897da6a6a750e3e
6
+ metadata.gz: a623d971fb524e0c7e17c433e13552465bc7d1ce5ebc2f9dbf6d417d994c5d65d5f2bbb31c2881a0eed23823ed39b76dd57bf2e72e5e9d31ac8696ace8c68a9e
7
+ data.tar.gz: e5bec3f0def4897570ea9bb75e5b440c308e258019f3bf7c58fd2b3a10becbc812d6276e1648ebf396cae380cfffd4b6ced6be2ab7214177561fc7b7d7c2fd92
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in activemodel-ipaddr_validator.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'coveralls', require: false
8
+ end
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # activemodel-ipaddr_validator [![Build Status](https://travis-ci.org/increments/activemodel-ipaddr_validator.svg?branch=master)](https://travis-ci.org/increments/activemodel-ipaddr_validator)
1
+ # activemodel-ipaddr_validator
2
+
3
+ [![Build Status](https://travis-ci.org/yuku-t/activemodel-ipaddr_validator.svg?branch=master)](https://travis-ci.org/yuku-t/activemodel-ipaddr_validator) [![Code Climate](https://codeclimate.com/github/yuku-t/activemodel-ipaddr_validator/badges/gpa.svg)](https://codeclimate.com/github/yuku-t/activemodel-ipaddr_validator) [![Coverage Status](https://coveralls.io/repos/yuku-t/activemodel-ipaddr_validator/badge.svg)](https://coveralls.io/r/yuku-t/activemodel-ipaddr_validator) [![Dependency Status](https://gemnasium.com/yuku-t/activemodel-ipaddr_validator.svg)](https://gemnasium.com/yuku-t/activemodel-ipaddr_validator)
4
+
2
5
 
3
6
  ## Usage
4
7
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Yuku Takahashi']
9
9
  spec.email = ['yuku@qiita.com']
10
10
  spec.summary = 'A IPv4 and IPv6 validator for Rails 3 and 4.'
11
- spec.homepage = 'https://github.com/increments/activemodel-ipaddr_validator'
11
+ spec.homepage = 'https://github.com/yuku-t/activemodel-ipaddr_validator'
12
12
  spec.license = 'MIT'
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0")
@@ -11,8 +11,8 @@ class IpaddrValidator < ActiveModel::EachValidator
11
11
  else
12
12
  [value]
13
13
  end
14
- array.all? do |string|
15
- validate_single_ipaddr(string, options)
14
+ array.all? do |value|
15
+ validate_single_ipaddr(value, options)
16
16
  end
17
17
  end
18
18
 
@@ -22,8 +22,13 @@ class IpaddrValidator < ActiveModel::EachValidator
22
22
 
23
23
  private
24
24
 
25
- def validate_single_ipaddr(string, options)
26
- ip = IPAddr.new(string)
25
+ def validate_single_ipaddr(value, options)
26
+ ip =
27
+ if value.is_a?(IPAddr)
28
+ value
29
+ else
30
+ IPAddr.new(value)
31
+ end
27
32
  case
28
33
  when options[:ipv4] && ip.ipv4?
29
34
  true
@@ -1,3 +1,3 @@
1
1
  class IpaddrValidator
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -38,6 +38,41 @@ shared_examples_for 'invalid array is given', given: :invalid_array do
38
38
  end
39
39
  end
40
40
 
41
+ shared_examples_for 'valid IPv4 IPAddr is given', given: :ipv4_ipaddr do
42
+ let(:value) do
43
+ IPAddr.new('192.168.2.0/24')
44
+ end
45
+ end
46
+
47
+ shared_examples_for 'valid IPv6 IPAddr is given', given: :ipv6_ipaddr do
48
+ let(:value) do
49
+ IPAddr.new('3ffe:505:2::1')
50
+ end
51
+ end
52
+
53
+ shared_examples_for 'valid IPv4 array of IPAddrs is given', given: :ipv4_array_ipaddr do
54
+ let(:value) do
55
+ [IPAddr.new('192.168.2.0/24'), IPAddr.new('192.168.3.0/24')]
56
+ end
57
+ end
58
+
59
+ shared_examples_for 'valid IPv6 array of IPAddrs is given', given: :ipv6_array_ipaddr do
60
+ let(:value) do
61
+ [IPAddr.new('3ffe:505:2::1'), IPAddr.new('3ffe:505:2::2')]
62
+ end
63
+ end
64
+
65
+ shared_examples_for 'invalid string is given', given: :invalid_ipaddr do
66
+ let(:value) do
67
+ nil
68
+ end
69
+ end
70
+
71
+ shared_examples_for 'invalid array is given', given: :invalid_array_ipaddr do
72
+ let(:value) do
73
+ [nil]
74
+ end
75
+ end
41
76
  # Shared examples for options.
42
77
 
43
78
  IpaddrValidator.default_options.keys.product([true, false]).each do |option, value|
@@ -62,42 +97,74 @@ describe IpaddrValidator do
62
97
  described_class.valid?(value, options)
63
98
  end
64
99
 
65
- context 'when a valid IPv4 string is given', given: :ipv4 do
66
- context 'and ipv4 option is true', ipv4: true do
67
- context 'and array option is true', array: true do
68
- it { should be_falsey }
100
+ context 'when strings are given' do
101
+ context 'when a valid IPv4 string is given', given: :ipv4 do
102
+ context 'and ipv4 option is true', ipv4: true do
103
+ context 'and array option is true', array: true do
104
+ it { should be_falsey }
105
+ end
106
+
107
+ context 'and array option is false', array: false do
108
+ it { should be_truthy }
109
+ end
69
110
  end
70
111
 
71
- context 'and array option is false', array: false do
72
- it { should be_truthy }
112
+ context 'and ipv4 option is false', ipv4: false do
113
+ it { should be_falsey }
73
114
  end
74
115
  end
75
116
 
76
- context 'and ipv4 option is false', ipv4: false do
77
- it { should be_falsey }
78
- end
79
- end
117
+ context 'when a valid IPv6 string is given', given: :ipv6 do
118
+ context 'and ipv6 option is true', ipv6: true do
119
+ context 'and array option is true', array: true do
120
+ it { should be_falsey }
121
+ end
80
122
 
81
- context 'when a valid IPv6 string is given', given: :ipv6 do
82
- context 'and ipv6 option is true', ipv6: true do
83
- context 'and array option is true', array: true do
123
+ context 'and array option is false', array: false do
124
+ it { should be_truthy }
125
+ end
126
+ end
127
+
128
+ context 'and ipv6 option is false', ipv6: false do
84
129
  it { should be_falsey }
85
130
  end
131
+ end
86
132
 
87
- context 'and array option is false', array: false do
88
- it { should be_truthy }
133
+ context 'when a valid IPv4 array is given', given: :ipv4_array do
134
+ context 'and ipv4 option is true', ipv4: true do
135
+ context 'and array option is true', array: true do
136
+ it { should be_truthy }
137
+ end
138
+
139
+ context 'and array option is false', array: false do
140
+ it { should be_falsey }
141
+ end
142
+ end
143
+
144
+ context 'and ipv4 option is false', ipv4: false do
145
+ it { should be_falsey }
89
146
  end
90
147
  end
91
148
 
92
- context 'and ipv6 option is false', ipv6: false do
93
- it { should be_falsey }
149
+ context 'when a valid IPv6 array is given', given: :ipv6_array do
150
+ context 'and ipv6 option is true', ipv6: true do
151
+ context 'and array option is true', array: true do
152
+ it { should be_truthy }
153
+ end
154
+
155
+ context 'and array option is false', array: false do
156
+ it { should be_falsey }
157
+ end
158
+ end
159
+
160
+ context 'and ipv6 option is false', ipv6: false do
161
+ it { should be_falsey }
162
+ end
94
163
  end
95
- end
96
164
 
97
- context 'when a valid IPv4 array is given', given: :ipv4_array do
98
- context 'and ipv4 option is true', ipv4: true do
165
+ context 'when an invalid string is given', given: :invalid do
99
166
  context 'and array option is true', array: true do
100
- it { should be_truthy }
167
+ it { should be_falsey }
101
168
  end
102
169
 
103
170
  context 'and array option is false', array: false do
@@ -105,44 +172,100 @@ describe IpaddrValidator do
105
172
  end
106
173
  end
107
174
 
108
- context 'and ipv4 option is false', ipv4: false do
109
- it { should be_falsey }
175
+ context 'when an invalid array is given', given: :invalid_array do
176
+ context 'and array option is true', array: true do
177
+ it { should be_falsey }
178
+ end
179
+
180
+ context 'and array option is false', array: false do
181
+ it { should be_falsey }
182
+ end
110
183
  end
111
184
  end
112
185
 
113
- context 'when a valid IPv6 array is given', given: :ipv6_array do
114
- context 'and ipv6 option is true', ipv6: true do
115
- context 'and array option is true', array: true do
116
- it { should be_truthy }
186
+ context 'when IPAddrs are given' do
187
+ context 'when a valid IPv4 IPAddr is given', given: :ipv4_ipaddr do
188
+ context 'and ipv4 option is true', ipv4: true do
189
+ context 'and array option is true', array: true do
190
+ it { should be_falsey }
191
+ end
192
+
193
+ context 'and array option is false', array: false do
194
+ it { should be_truthy }
195
+ end
117
196
  end
118
197
 
119
- context 'and array option is false', array: false do
198
+ context 'and ipv4 option is false', ipv4: false do
120
199
  it { should be_falsey }
121
200
  end
122
201
  end
123
202
 
124
- context 'and ipv6 option is false', ipv6: false do
125
- it { should be_falsey }
203
+ context 'when a valid IPv6 IPAddr is given', given: :ipv6_ipaddr do
204
+ context 'and ipv6 option is true', ipv6: true do
205
+ context 'and array option is true', array: true do
206
+ it { should be_falsey }
207
+ end
208
+
209
+ context 'and array option is false', array: false do
210
+ it { should be_truthy }
211
+ end
212
+ end
213
+
214
+ context 'and ipv6 option is false', ipv6: false do
215
+ it { should be_falsey }
216
+ end
126
217
  end
127
- end
128
218
 
129
- context 'when an invalid string is given', given: :invalid do
130
- context 'and array option is true', array: true do
131
- it { should be_falsey }
219
+ context 'when a valid IPv4 array of IPAddrs is given', given: :ipv4_array_ipaddr do
220
+ context 'and ipv4 option is true', ipv4: true do
221
+ context 'and array option is true', array: true do
222
+ it { should be_truthy }
223
+ end
224
+
225
+ context 'and array option is false', array: false do
226
+ it { should be_falsey }
227
+ end
228
+ end
229
+
230
+ context 'and ipv4 option is false', ipv4: false do
231
+ it { should be_falsey }
232
+ end
132
233
  end
133
234
 
134
- context 'and array option is false', array: false do
135
- it { should be_falsey }
235
+ context 'when a valid IPv6 array of IPAddrs is given', given: :ipv6_array_ipaddr do
236
+ context 'and ipv6 option is true', ipv6: true do
237
+ context 'and array option is true', array: true do
238
+ it { should be_truthy }
239
+ end
240
+
241
+ context 'and array option is false', array: false do
242
+ it { should be_falsey }
243
+ end
244
+ end
245
+
246
+ context 'and ipv6 option is false', ipv6: false do
247
+ it { should be_falsey }
248
+ end
136
249
  end
137
- end
138
250
 
139
- context 'when an invalid array is given', given: :invalid_array do
140
- context 'and array option is true', array: true do
141
- it { should be_falsey }
251
+ context 'when an invalid IPAddr is given', given: :invalid_ipaddr do
252
+ context 'and array option is true', array: true do
253
+ it { should be_falsey }
254
+ end
255
+
256
+ context 'and array option is false', array: false do
257
+ it { should be_falsey }
258
+ end
142
259
  end
143
260
 
144
- context 'and array option is false', array: false do
145
- it { should be_falsey }
261
+ context 'when an invalid array of IPAddrs is given', given: :invalid_array_ipaddr do
262
+ context 'and array option is true', array: true do
263
+ it { should be_falsey }
264
+ end
265
+
266
+ context 'and array option is false', array: false do
267
+ it { should be_falsey }
268
+ end
146
269
  end
147
270
  end
148
271
  end
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'active_model'
2
5
  require 'ipaddr_validator'
3
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel-ipaddr_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuku Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".coverrails.yml"
76
77
  - ".gitignore"
77
78
  - ".travis.yml"
78
79
  - Gemfile
@@ -87,7 +88,7 @@ files:
87
88
  - lib/ipaddr_validator/version.rb
88
89
  - spec/ipaddr_validator_spec.rb
89
90
  - spec/spec_helper.rb
90
- homepage: https://github.com/increments/activemodel-ipaddr_validator
91
+ homepage: https://github.com/yuku-t/activemodel-ipaddr_validator
91
92
  licenses:
92
93
  - MIT
93
94
  metadata: {}
@@ -107,8 +108,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  version: '0'
108
109
  requirements: []
109
110
  rubyforge_project:
110
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.4.5.1
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: A IPv4 and IPv6 validator for Rails 3 and 4.
114
115
  test_files: []
116
+ has_rdoc: