data-validator 1.0.5 → 1.1.0

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
- SHA256:
3
- metadata.gz: a17797f11cd84b48bd15ac9e12ba2eab7fc0bd0da5ac251f6ed04fb361a75981
4
- data.tar.gz: 6498c18fb66ec1908ff054f899e1c8895edc0ebf6755a045152513576b86b050
2
+ SHA1:
3
+ metadata.gz: be3b60e45735bbc9a89a15f341008b2a4602ebca
4
+ data.tar.gz: ac9ccdd6eaae3944b0c766ca17af0f329bd8546a
5
5
  SHA512:
6
- metadata.gz: 34647edb3d7c4f609802a973078be05e6a458cdeb3510cb97ef0d6ace03c946e5e29c103dc829d6ee25bf438d59cb01ce390c42f27c6ca1185a80218a94be3b5
7
- data.tar.gz: 775e48023d6083a316e5cefbd3430d35a0ebe543fa18a842992aa3e8839b02d6854f32686501f0d97693158fe55985fceffa8be61cd4ffe5c28145d83a234576
6
+ metadata.gz: 30ef98f00a118cc7dc5e4b5dc2c034cdc8b0af96b01a451fe43abca520f98259419385ece5057ea5908a165eff9aeb2ae75039d29efd2a9a5b11ca2b0797d46b
7
+ data.tar.gz: 8ddce94eaf73696f009aaed3307a5467d0e7b4acb750fc5343494ab3c42000192bca6f6ad3b54dbb2d56cd9a205ab83774e7bc14ca2c96307e56c058bec4c107
@@ -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.5"
23
+ Data::Validator::VERSION = "1.1.0"
@@ -20,7 +20,6 @@
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'
24
23
  Data::Validator = Class.new # @!parse class Data::Validator; end
25
24
  require_relative "validator/version"
26
25
 
@@ -129,6 +128,16 @@ class Data::Validator
129
128
  case extension
130
129
  when 'AllowExtra' then
131
130
  @rule[:allow_extra] = true
131
+ if @rule.has_key? :rule
132
+ case
133
+ when @isa == Hash then
134
+ @rule[:rule].each_value do |rule|
135
+ rule.with extension if rule.is_a? self.class
136
+ end
137
+ else
138
+ @rule[:rule].with extension if @rule[:rule].is_a? self.class
139
+ end
140
+ end
132
141
  else
133
142
  raise ArgumentError, "unsupported extension #{extension}"
134
143
  end
@@ -212,6 +221,12 @@ class Data::Validator
212
221
  raise Error, "#{x} or #{y} missing"
213
222
  end
214
223
  end
224
+ unless @rule[:allow_extra] then
225
+ extra = (actual.keys - @rule[:rule].keys)
226
+ unless extra.empty? then
227
+ raise Error, "extra key(s): #{extra.inspect}"
228
+ end
229
+ end
215
230
  return actual
216
231
  end
217
232
 
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data-validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urabe, Shyouhei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2016-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,7 +121,6 @@ files:
121
121
  - README.md
122
122
  - Rakefile
123
123
  - data-validator.gemspec
124
- - lib/data.rb
125
124
  - lib/data/validator.rb
126
125
  - lib/data/validator/error.rb
127
126
  - lib/data/validator/recursive.rb
@@ -159,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
158
  version: '0'
160
159
  requirements: []
161
160
  rubyforge_project:
162
- rubygems_version: 2.7.6
161
+ rubygems_version: 2.5.1
163
162
  signing_key:
164
163
  specification_version: 4
165
164
  summary: p5-Data-Validator / p5-Data-Validator-Recursive port
@@ -177,3 +176,4 @@ test_files:
177
176
  - test/xaicron/01_new.rb
178
177
  - test/xaicron/02_validate.rb
179
178
  - test/xaicron/03_arrayref.rb
179
+ has_rdoc:
data/lib/data.rb DELETED
@@ -1,40 +0,0 @@
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