data-validator 1.0.4 → 1.1.3

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
- SHA1:
3
- metadata.gz: 4db89bd57d2ff864036a732c664de3567c7a0484
4
- data.tar.gz: 5180ae2f97bd74c61fdc086f6be9b18975fb1069
2
+ SHA256:
3
+ metadata.gz: 50f3566cc5d434fa1877142a1ce9e993277f3a0d617d2030be78ae801c96113c
4
+ data.tar.gz: 18949992ca7ee9ced52cf8fc13db55c8689c37f59655f1ae10af4ee88ea52196
5
5
  SHA512:
6
- metadata.gz: 30ba9963cd4153cafea0f395e93002c3ef23496538033950514132017492c35d8226110f792c2224ba22184534b560ef53aeb2660f24a0d56423209c69f185a4
7
- data.tar.gz: 4c8a6e91abd7ae018cbbc891d387ed1da263deae4e5094b60c9af32ee911176efe1fa848fe6a9b15e5cf698deabf9dd095915b802e2d7b10e2ec03fe7da56b08
6
+ metadata.gz: e872ba1fb97cd0ed444735cb5f2d53b21f25c6673b51e31adc630dd5a47d93d0d2a457d0b8190042b5d8daa6999abff29cd066b203f3705c108cdc7446bf8822
7
+ data.tar.gz: e90c0de40e03bcf5937cba724f322f99f66f0e8dd3d9a721aa7e3719008f923402fcba83fb59cccfb0a41f1bbfb5e0e32476e5778a317a0621efa9496041e689
@@ -45,12 +45,12 @@ Gem::Specification.new do |spec|
45
45
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
46
46
  spec.require_paths = ["lib"]
47
47
 
48
- spec.required_ruby_version = '>= 1.9.3'
49
- spec.add_development_dependency 'bundler', '~> 1.5'
50
- spec.add_development_dependency 'rake', '~> 10.3'
51
- spec.add_development_dependency 'rdoc', '~> 4.0'
52
- spec.add_development_dependency 'yard', '~> 0.8'
53
- spec.add_development_dependency 'test-unit', '~> 3.0'
54
- spec.add_development_dependency 'simplecov', '>= 0'
55
- spec.add_development_dependency 'pry', '~> 0.10'
48
+ spec.required_ruby_version = '>= 1.9.3'
49
+ spec.add_development_dependency 'bundler'
50
+ spec.add_development_dependency 'rake'
51
+ spec.add_development_dependency 'rdoc'
52
+ spec.add_development_dependency 'yard'
53
+ spec.add_development_dependency 'test-unit'
54
+ spec.add_development_dependency 'simplecov'
55
+ spec.add_development_dependency 'pry'
56
56
  end
data/lib/data.rb ADDED
@@ -0,0 +1,40 @@
1
+ #! /your/favourite/path/to/ruby
2
+ # -*- mode: ruby; coding: utf-8; indent-tabs-mode: nil; ruby-indent-level 2 -*-
3
+
4
+ # Copyright (c) 2018 Urabe, Shyouhei
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ # Toplevel namespace `::Data` got deprecated, and will eventually be disappear.
25
+ # However we are using it because p5-Data-Validator is in this namespace. This
26
+ # has nothing to do with the deprecation of Ruby's `::Data`.
27
+ if !defined? ::Data then
28
+ Data = Class.new # create one here
29
+ elsif defined? ::Warning then
30
+ # We have to shut up the deprecation warning.
31
+ class << Warning
32
+ prepend Module.new {
33
+ def warn str
34
+ super unless /::Data is deprecated/ =~ str
35
+ end
36
+ }
37
+ end
38
+ else
39
+ # This ruby is very old. We don't have to do anything.
40
+ end
@@ -20,6 +20,7 @@
20
20
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  # SOFTWARE.
23
+ require_relative '../data'
23
24
  Data::Validator = Class.new # @!parse class Data::Validator; end
24
25
  require_relative "validator/version"
25
26
 
@@ -128,6 +129,16 @@ class Data::Validator
128
129
  case extension
129
130
  when 'AllowExtra' then
130
131
  @rule[:allow_extra] = true
132
+ if @rule.has_key? :rule
133
+ case
134
+ when @isa == Hash then
135
+ @rule[:rule].each_value do |rule|
136
+ rule.with extension if rule.is_a? self.class
137
+ end
138
+ else
139
+ @rule[:rule].with extension if @rule[:rule].is_a? self.class
140
+ end
141
+ end
131
142
  else
132
143
  raise ArgumentError, "unsupported extension #{extension}"
133
144
  end
@@ -166,6 +177,8 @@ class Data::Validator
166
177
  fillin << key
167
178
  elsif rule[:optional] then
168
179
  # ok
180
+ elsif @isa then
181
+ missing << key
169
182
  elsif @rule[:allow_extra] then
170
183
  # ok
171
184
  else
@@ -211,6 +224,12 @@ class Data::Validator
211
224
  raise Error, "#{x} or #{y} missing"
212
225
  end
213
226
  end
227
+ unless @rule[:allow_extra] then
228
+ extra = (actual.keys - @rule[:rule].keys)
229
+ unless extra.empty? then
230
+ raise Error, "extra key(s): #{extra.inspect}"
231
+ end
232
+ end
214
233
  return actual
215
234
  end
216
235
 
@@ -20,4 +20,4 @@
20
20
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  # SOFTWARE.
23
- Data::Validator::VERSION = "1.0.4"
23
+ Data::Validator::VERSION = "1.1.3"
@@ -0,0 +1,30 @@
1
+ require 'test-unit'
2
+ require 'data/validator'
3
+
4
+ class Test02Validate < Test::Unit::TestCase
5
+ test 'requires with AllowExtra' do
6
+ rule = Data::Validator::Recursive.new(
7
+ 'foo' => String,
8
+ 'bar' => { isa: Integer, default: 1 },
9
+ 'baz' => {
10
+ isa: Hash,
11
+ with: 'AllowExtra',
12
+ rule: {
13
+ 'hoge' => { isa: String }, # requires
14
+ 'fuga' => Integer,
15
+ },
16
+ },
17
+ ).with('AllowExtra')
18
+
19
+ input = {
20
+ 'foo' => 'xxx',
21
+ 'baz' => {
22
+ 'fuga' => 123,
23
+ 'extra_param_in_baz' => 1,
24
+ },
25
+ 'extra_param' => 1,
26
+ }
27
+
28
+ assert_raise_message(/missing/) { rule.validate(input) }
29
+ end
30
+ end
@@ -22,5 +22,8 @@ class Test001Basic < Test::Unit::TestCase
22
22
 
23
23
  assert_raise_message(/foo/) { v.validate() }
24
24
  assert_raise_message(/foo/) { v.validate({'foo' => 'bar'}) }
25
+ assert_raise_message(/baz|qux/) {
26
+ v.validate({'foo' => 0, 'baz' => 42, 'qux' => 100 })
27
+ }
25
28
  end
26
29
  end
@@ -6,7 +6,7 @@ class Test104ExtraArgs < Test::Unit::TestCase
6
6
  def test_test
7
7
  v = Data::Validator.new(
8
8
  'foo' => { },
9
- )
9
+ ).with('AllowExtra')
10
10
 
11
11
  args = v.validate('foo' => 42, 'bar' => 15)
12
12
  assert { args == {'foo' => 42, 'bar' => 15} }
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urabe, Shyouhei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-16 00:00:00.000000000 Z
11
+ date: 2021-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.3'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.3'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '4.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0.8'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0.8'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: simplecov
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0.10'
103
+ version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '0.10'
110
+ version: '0'
111
111
  description: for gfx fan and xaicron fan
112
112
  email:
113
113
  - shyouhei@ruby-lang.org
@@ -121,11 +121,13 @@ files:
121
121
  - README.md
122
122
  - Rakefile
123
123
  - data-validator.gemspec
124
+ - lib/data.rb
124
125
  - lib/data/validator.rb
125
126
  - lib/data/validator/error.rb
126
127
  - lib/data/validator/recursive.rb
127
128
  - lib/data/validator/version.rb
128
129
  - test/01_orclass.rb
130
+ - test/02_validate_requires_allowextra.rb
129
131
  - test/gfx/000_load.rb
130
132
  - test/gfx/001_basic.rb
131
133
  - test/gfx/002_isa.rb
@@ -157,13 +159,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  - !ruby/object:Gem::Version
158
160
  version: '0'
159
161
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.5.1
162
+ rubygems_version: 3.3.0.dev
162
163
  signing_key:
163
164
  specification_version: 4
164
165
  summary: p5-Data-Validator / p5-Data-Validator-Recursive port
165
166
  test_files:
166
167
  - test/01_orclass.rb
168
+ - test/02_validate_requires_allowextra.rb
167
169
  - test/gfx/000_load.rb
168
170
  - test/gfx/001_basic.rb
169
171
  - test/gfx/002_isa.rb
@@ -176,4 +178,3 @@ test_files:
176
178
  - test/xaicron/01_new.rb
177
179
  - test/xaicron/02_validate.rb
178
180
  - test/xaicron/03_arrayref.rb
179
- has_rdoc: