keyvalidatable 0.1.0 → 0.2.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
2
  SHA256:
3
- metadata.gz: c1533215222b427b2bd59e107dc6ae0db9f92cc384641663f3290ec91e381dbb
4
- data.tar.gz: 181510cf3792e1b489a8197f552791691453f87f7285d0130a599a70d520841a
3
+ metadata.gz: a819ae40e868ea5e3bbfe95d67a32bc1fb1c5c774c48bff656c641910fd40260
4
+ data.tar.gz: 3ad5d3839812989e34ebf8065f46bbcbae2cf41271fadfea4187d9aa5d8f18e7
5
5
  SHA512:
6
- metadata.gz: b5b552d7036a870c696c6d7dc756e3aab2b0509aac9b19552f4380a36291d002e8cf0460995681a59670591263c792c108f29cc8d1e015316a45d0c1d05d13e0
7
- data.tar.gz: 901001a2d0d2b6248f2612098c3518fe3cada0a83de418a33e5677d30b22dd239fc23c22864d1ceb35d516e68bd05385fd7c9001dd255db6470902b86201d051
6
+ metadata.gz: acf72f303667cb531bb26505e8199df01b870d5df26dfddbc2189821df30804c5e12b0a2263946d2b77651aacfa19bb6a54a582c2259cb158f29045b28e0188d
7
+ data.tar.gz: 3158de1da752e047354e2942a1c9bcfb8c2f59f6ee44ebf7531ee50e6ec3c167d3f294dbd93f88ddfd10e87c089af114431f0ab3db54916f757c9b3468a2ff51
File without changes
data/README.md CHANGED
@@ -1,33 +1,35 @@
1
- keyvalidatable
2
- ==============
1
+ # keyvalidatable
3
2
 
4
- [![Build Status](https://secure.travis-ci.org/kachick/keyvalidatable.png)](http://travis-ci.org/kachick/keyvalidatable)
3
+ ![Build Status](https://github.com/kachick/keyvalidatable/actions/workflows/test_behaviors.yml/badge.svg?branch=main)
5
4
  [![Gem Version](https://badge.fury.io/rb/keyvalidatable.png)](http://badge.fury.io/rb/keyvalidatable)
6
- [![Dependency Status](https://gemnasium.com/kachick/keyvalidatable.svg)](https://gemnasium.com/kachick/keyvalidatable)
7
-
8
- Description
9
- -----------
10
5
 
11
6
  Validate shortage/excess keys in pairs.
12
7
 
13
- Usage
14
- -----
8
+ ## Usage
9
+
10
+ ### Install
11
+
12
+ Require Ruby 2.5 or later
15
13
 
16
- ### Validate option parameters(hash-argument)
14
+ Add this line to your application/library's `Gemfile` is needed in basic use-case
15
+
16
+ ```ruby
17
+ gem 'keyvalidatable', '>= 0.2.0', '< 0.3.0'
18
+ ```
19
+
20
+ ### Overview
17
21
 
18
22
  ```ruby
19
23
  require 'keyvalidatable'
20
-
21
- class Foo
22
24
 
25
+ class Foo
23
26
  def func(options)
24
27
  KeyValidatable.validate_keys options, must: [:a, :b], let: [:c]
25
28
 
26
29
  p "#{options} is valid"
27
- rescue
28
- p $!
30
+ rescue => err
31
+ p err
29
32
  end
30
-
31
33
  end
32
34
 
33
35
  foo = Foo.new
@@ -37,30 +39,7 @@ foo.func(a: 1, b: 2) #=> "{:a=>1, :b=>2} is valid"
37
39
  foo.func(a: 1, b: 2, c: 3, d: 4) #=> InvalidKeysError: Shortage: [] / Excess: [:d]
38
40
  ```
39
41
 
40
- Requirements
41
- ------------
42
-
43
- * Ruby - [2.2 or later](http://travis-ci.org/#!/kachick/keyvalidatable)
44
-
45
- Install
46
- -------
47
-
48
- ```shell
49
- $ gem install keyvalidatable
50
- ```
51
-
52
- Link
53
- ----
54
-
55
- * [code](https://github.com/kachick/keyvalidatable)
56
- * [API](http://www.rubydoc.info/github/kachick/keyvalidatable)
57
- * [issues](https://github.com/kachick/keyvalidatable/issues)
58
- * [CI](http://travis-ci.org/#!/kachick/keyvalidatable)
59
- * [gem](https://rubygems.org/gems/keyvalidatable)
60
-
61
- License
62
- -------
42
+ ## Links
63
43
 
64
- The MIT X11 License
65
- Copyright (c) 2012 Kenichi Kamiya
66
- See MIT-LICENSE for further details.
44
+ - [Repository](https://github.com/kachick/keyvalidatable)
45
+ - [API documents](https://kachick.github.io/keyvalidatable)
@@ -1,28 +1,23 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
3
+
2
4
  # Copyright (c) 2012 Kenichi Kamiya
3
5
 
4
6
  require_relative 'keyvalidatable/errors'
5
7
  require_relative 'keyvalidatable/singleton_class'
8
+ require_relative 'keyvalidatable/version'
6
9
 
7
10
  module KeyValidatable
8
-
9
- # @group Instance methods for extended pair objects
10
-
11
11
  # @param [Hash] requirements
12
12
  def validate_keys(requirements)
13
- KeyValidatable.__send__ __callee__, self, requirements
13
+ KeyValidatable.__send__(__callee__, self, requirements)
14
14
  end
15
-
16
15
  alias_method :validate_members, :validate_keys
17
16
  alias_method :assert_keys, :validate_keys
18
-
17
+
19
18
  # @param [Hash] requirements
20
19
  def valid_keys?(requirements)
21
- KeyValidatable.__send__ __callee__, self, requirements
20
+ KeyValidatable.__send__(__callee__, self, requirements)
22
21
  end
23
-
24
22
  alias_method :valid_members?, :valid_keys?
25
-
26
- # @endgroup
27
-
28
23
  end
@@ -1,7 +1,6 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
2
3
 
3
4
  module KeyValidatable
4
-
5
5
  class InvalidKeysError < KeyError; end
6
-
7
6
  end
@@ -0,0 +1,16 @@
1
+ # coding: us-ascii
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../keyvalidatable'
5
+
6
+ module KeyValidatable
7
+ module Refinements
8
+ refine Hash do
9
+ include KeyValidatable
10
+ end
11
+
12
+ refine Struct do
13
+ include KeyValidatable
14
+ end
15
+ end
16
+ end
@@ -1,9 +1,8 @@
1
1
  # coding: us-ascii
2
+ # frozen_string_literal: true
2
3
 
3
4
  module KeyValidatable
4
-
5
5
  class << self
6
-
7
6
  # @param [Hash, #to_hash, #to_h, Struct, #keys, #members] key_value_pairs
8
7
  # @param [Hash] requirements
9
8
  # @option requirements [Array] :must
@@ -11,7 +10,7 @@ module KeyValidatable
11
10
  # @return [nil]
12
11
  # @raise [InvalidKeysError] if pairs is deficient for requirements
13
12
  def validate_keys_in_pairs(key_value_pairs, requirements)
14
- validate_array keys_for(key_value_pairs), requirements
13
+ validate_array(keys_for(key_value_pairs), requirements)
15
14
  end
16
15
 
17
16
  alias_method :validate_keys, :validate_keys_in_pairs
@@ -29,17 +28,17 @@ module KeyValidatable
29
28
  # @return [nil]
30
29
  # @raise [InvalidKeysError] if pairs is deficient for requirements
31
30
  def validate_array(keys, requirements)
32
- assert_requirements requirements
31
+ assert_requirements(requirements)
33
32
  musts, lets = musts_for(requirements), lets_for(requirements)
34
-
35
- shortage_keys = shortage_elements keys.to_ary, musts
36
- excess_keys = excess_elements keys.to_ary, musts, lets
37
-
33
+
34
+ shortage_keys = shortage_elements(keys.to_ary, musts)
35
+ excess_keys = excess_elements(keys.to_ary, musts, lets)
36
+
38
37
  unless [*shortage_keys, *excess_keys].empty?
39
38
  raise InvalidKeysError,
40
39
  "Shortage: #{shortage_keys} / Excess: #{excess_keys}"
41
40
  end
42
-
41
+
43
42
  nil
44
43
  end
45
44
 
@@ -48,9 +47,9 @@ module KeyValidatable
48
47
  # @option requirements [Array] :must
49
48
  # @option requirements [Array] :let
50
49
  def valid_keys?(key_value_pairs, requirements)
51
- valid_array? keys_for(key_value_pairs), requirements
50
+ valid_array?(keys_for(key_value_pairs), requirements)
52
51
  end
53
-
52
+
54
53
  alias_method :valid_members?, :valid_keys?
55
54
 
56
55
  # @param [Array, #to_ary] keys
@@ -58,8 +57,8 @@ module KeyValidatable
58
57
  # @option requirements [Array] :must
59
58
  # @option requirements [Array] :let
60
59
  def valid_array?(keys, requirements)
61
- assert_requirements requirements
62
- validate_array keys, requirements
60
+ assert_requirements(requirements)
61
+ validate_array(keys, requirements)
63
62
  rescue InvalidKeysError
64
63
  false
65
64
  else
@@ -95,52 +94,50 @@ module KeyValidatable
95
94
  def shortage_elements(elements, musts)
96
95
  musts - elements
97
96
  end
98
-
97
+
99
98
  def excess_elements(elements, musts, lets)
100
99
  (elements - musts) - lets
101
100
  end
102
101
 
103
102
  # @param [Hash] requirements
104
103
  def assert_requirements(requirements)
105
- raise ArgumentError unless requirements.respond_to? :keys
104
+ raise ArgumentError unless requirements.respond_to?(:keys)
106
105
 
107
106
  unless (requirements.keys - [:must, :let]).empty?
108
107
  raise ArgumentError
109
108
  end
110
-
109
+
111
110
  musts, lets = requirements[:must], requirements[:let]
112
-
113
- if musts
111
+
112
+ if musts
114
113
  unless musts.kind_of?(Array) &&
115
- musts.all?{|key|key.respond_to?(:hash) && key.respond_to?(:eql?)}
114
+ musts.all? { |key| key.respond_to?(:hash) && key.respond_to?(:eql?) }
116
115
  raise TypeError
117
116
  end
118
117
  end
119
-
118
+
120
119
  if lets
121
120
  unless lets.kind_of?(Array) &&
122
- lets.all?{|key|key.respond_to?(:hash) && key.respond_to?(:eql?)}
121
+ lets.all? { |key| key.respond_to?(:hash) && key.respond_to?(:eql?) }
123
122
  raise TypeError
124
123
  end
125
124
  end
126
-
125
+
127
126
  unless musts || lets
128
127
  raise TypeError
129
128
  end
130
-
131
- if requirements.values.inject(&:+).empty?
129
+
130
+ if requirements.values.sum([]).empty?
132
131
  raise ArgumentError
133
132
  end
134
133
  end
135
-
134
+
136
135
  def musts_for(requirements)
137
136
  requirements[:must] || []
138
137
  end
139
-
138
+
140
139
  def lets_for(requirements)
141
140
  requirements[:let] || []
142
141
  end
143
-
144
142
  end
145
-
146
143
  end
@@ -0,0 +1,6 @@
1
+ # coding: us-ascii
2
+ # frozen_string_literal: true
3
+
4
+ module KeyValidatable
5
+ VERSION = '0.2.0'
6
+ end
metadata CHANGED
@@ -1,22 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keyvalidatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2021-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: yard
14
+ name: declare
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: irb
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 1.3.5
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.3.5
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: irb-power_assert
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '='
58
+ - !ruby/object:Gem::Version
59
+ version: 0.0.2
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '='
65
+ - !ruby/object:Gem::Version
66
+ version: 0.0.2
67
+ - !ruby/object:Gem::Dependency
68
+ name: warning
15
69
  requirement: !ruby/object:Gem::Requirement
16
70
  requirements:
17
71
  - - ">="
18
72
  - !ruby/object:Gem::Version
19
- version: 0.9.11
73
+ version: 1.2.0
20
74
  - - "<"
21
75
  - !ruby/object:Gem::Version
22
76
  version: '2.0'
@@ -26,7 +80,7 @@ dependencies:
26
80
  requirements:
27
81
  - - ">="
28
82
  - !ruby/object:Gem::Version
29
- version: 0.9.11
83
+ version: 1.2.0
30
84
  - - "<"
31
85
  - !ruby/object:Gem::Version
32
86
  version: '2.0'
@@ -36,27 +90,27 @@ dependencies:
36
90
  requirements:
37
91
  - - ">="
38
92
  - !ruby/object:Gem::Version
39
- version: '10'
93
+ version: 13.0.3
40
94
  - - "<"
41
95
  - !ruby/object:Gem::Version
42
- version: '20'
96
+ version: '20.0'
43
97
  type: :development
44
98
  prerelease: false
45
99
  version_requirements: !ruby/object:Gem::Requirement
46
100
  requirements:
47
101
  - - ">="
48
102
  - !ruby/object:Gem::Version
49
- version: '10'
103
+ version: 13.0.3
50
104
  - - "<"
51
105
  - !ruby/object:Gem::Version
52
- version: '20'
106
+ version: '20.0'
53
107
  - !ruby/object:Gem::Dependency
54
- name: bundler
108
+ name: yard
55
109
  requirement: !ruby/object:Gem::Requirement
56
110
  requirements:
57
111
  - - ">="
58
112
  - !ruby/object:Gem::Version
59
- version: '1.10'
113
+ version: 0.9.26
60
114
  - - "<"
61
115
  - !ruby/object:Gem::Version
62
116
  version: '2'
@@ -66,55 +120,133 @@ dependencies:
66
120
  requirements:
67
121
  - - ">="
68
122
  - !ruby/object:Gem::Version
69
- version: '1.10'
123
+ version: 0.9.26
70
124
  - - "<"
71
125
  - !ruby/object:Gem::Version
72
126
  version: '2'
73
127
  - !ruby/object:Gem::Dependency
74
- name: declare
128
+ name: rubocop
75
129
  requirement: !ruby/object:Gem::Requirement
76
130
  requirements:
77
- - - "~>"
131
+ - - ">="
78
132
  - !ruby/object:Gem::Version
79
- version: 0.0.6
133
+ version: 1.15.0
134
+ - - "<"
135
+ - !ruby/object:Gem::Version
136
+ version: 1.16.0
80
137
  type: :development
81
138
  prerelease: false
82
139
  version_requirements: !ruby/object:Gem::Requirement
83
140
  requirements:
84
- - - "~>"
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 1.15.0
144
+ - - "<"
145
+ - !ruby/object:Gem::Version
146
+ version: 1.16.0
147
+ - !ruby/object:Gem::Dependency
148
+ name: rubocop-rake
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: 0.5.1
154
+ - - "<"
155
+ - !ruby/object:Gem::Version
156
+ version: 0.6.0
157
+ type: :development
158
+ prerelease: false
159
+ version_requirements: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: 0.5.1
164
+ - - "<"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.6.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-performance
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: 1.11.3
174
+ - - "<"
175
+ - !ruby/object:Gem::Version
176
+ version: 1.12.0
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: 1.11.3
184
+ - - "<"
185
+ - !ruby/object:Gem::Version
186
+ version: 1.12.0
187
+ - !ruby/object:Gem::Dependency
188
+ name: rubocop-rubycw
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: 0.1.6
194
+ - - "<"
195
+ - !ruby/object:Gem::Version
196
+ version: 0.2.0
197
+ type: :development
198
+ prerelease: false
199
+ version_requirements: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: 0.1.6
204
+ - - "<"
205
+ - !ruby/object:Gem::Version
206
+ version: 0.2.0
207
+ - !ruby/object:Gem::Dependency
208
+ name: rubocop-md
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: 1.0.1
214
+ - - "<"
215
+ - !ruby/object:Gem::Version
216
+ version: 2.0.0
217
+ type: :development
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: 1.0.1
224
+ - - "<"
85
225
  - !ruby/object:Gem::Version
86
- version: 0.0.6
87
- description: Validate shortage/excess keys in pairs.
226
+ version: 2.0.0
227
+ description: " Validate shortage/excess keys in pairs\n"
88
228
  email:
89
229
  - kachick1+ruby@gmail.com
90
230
  executables: []
91
231
  extensions: []
92
232
  extra_rdoc_files: []
93
233
  files:
94
- - ".gitignore"
95
- - ".travis.yml"
96
- - ".yardopts"
97
- - Gemfile
98
- - MIT-LICENSE
234
+ - MIT-LICENSE.txt
99
235
  - README.md
100
- - Rakefile
101
- - example/README.rb
102
- - keyvalidatable.gemspec
103
236
  - lib/keyvalidatable.rb
104
- - lib/keyvalidatable/core_ext.rb
105
237
  - lib/keyvalidatable/errors.rb
238
+ - lib/keyvalidatable/refinements.rb
106
239
  - lib/keyvalidatable/singleton_class.rb
107
- - test/helper.rb
108
- - test/test_basic_for_keys_array.rb
109
- - test/test_basic_from_hash.rb
110
- - test/test_basic_from_struct.rb
111
- - test/test_let_from_hash.rb
112
- - test/test_let_from_struct.rb
240
+ - lib/keyvalidatable/version.rb
113
241
  homepage: https://github.com/kachick/keyvalidatable
114
242
  licenses:
115
243
  - MIT
116
- metadata: {}
117
- post_install_message:
244
+ metadata:
245
+ documentation_uri: https://kachick.github.io/keyvalidatable/
246
+ homepage_uri: https://github.com/kachick/keyvalidatable
247
+ source_code_uri: https://github.com/kachick/keyvalidatable
248
+ bug_tracker_uri: https://github.com/kachick/keyvalidatable/issues
249
+ post_install_message:
118
250
  rdoc_options: []
119
251
  require_paths:
120
252
  - lib
@@ -122,22 +254,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
254
  requirements:
123
255
  - - ">="
124
256
  - !ruby/object:Gem::Version
125
- version: '2.2'
257
+ version: 2.5.0
126
258
  required_rubygems_version: !ruby/object:Gem::Requirement
127
259
  requirements:
128
260
  - - ">="
129
261
  - !ruby/object:Gem::Version
130
262
  version: '0'
131
263
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.7.3
134
- signing_key:
264
+ rubygems_version: 3.2.15
265
+ signing_key:
135
266
  specification_version: 4
136
- summary: Validate shortage/excess keys in pairs.
137
- test_files:
138
- - test/helper.rb
139
- - test/test_basic_for_keys_array.rb
140
- - test/test_basic_from_hash.rb
141
- - test/test_basic_from_struct.rb
142
- - test/test_let_from_hash.rb
143
- - test/test_let_from_struct.rb
267
+ summary: Validate shortage/excess keys in pairs
268
+ test_files: []
data/.gitignore DELETED
@@ -1,34 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- coverage
6
- coverage.data
7
- InstalledFiles
8
- lib/bundler/man
9
- pkg
10
- rdoc
11
- spec/reports
12
- test/tmp
13
- test/version_tmp
14
- tmp
15
-
16
- # bundler
17
- vendor/
18
-
19
- # YARD artifacts
20
- .yardoc
21
- _yardoc
22
- doc/
23
-
24
- # tmp-old
25
- .old
26
-
27
- # editor
28
- *~
29
- *#*
30
- .redcar
31
-
32
- # other
33
- *.lock
34
- .rbx
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
-
3
- branches:
4
- only:
5
- - master
6
-
7
- rvm:
8
- - 2.5
9
- - 2.4
10
- - ruby-head
11
- - rbx-3
12
- - jruby-head
13
-
14
- matrix:
15
- allow_failures:
16
- - rvm: ruby-head
17
- - rvm: rbx-3
18
- - rvm: jruby-head
19
-
20
- before_install:
21
- - gem install bundler
data/.yardopts DELETED
@@ -1 +0,0 @@
1
- --readme README.md lib/**/*.rb --exclude core_ext - MIT-LICENSE
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'rake'
7
- end
8
-
9
- group :test do
10
- gem 'rake'
11
- end
data/Rakefile DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
-
4
- require 'rake/testtask'
5
-
6
- task default: [:test]
7
-
8
- Rake::TestTask.new do |tt|
9
- tt.verbose = true
10
- tt.warning = true
11
- end
data/example/README.rb DELETED
@@ -1,21 +0,0 @@
1
- $VERBOSE = true
2
-
3
- require_relative '../lib/keyvalidatable'
4
-
5
- class MyClass
6
-
7
- def my_method(options)
8
- KeyValidatable.validate_keys options, must: [:a, :b], let: [:c]
9
-
10
- p "#{options} is valid"
11
- rescue
12
- p $!
13
- end
14
-
15
- end
16
-
17
- my_obj = MyClass.new
18
- my_obj.my_method(a: 1, b: 2, c: 3) #=> "{:a=>1, :b=>2, :c=>3} is valid"
19
- my_obj.my_method(a: 1, c: 3) #=> #<KeyValidatable::InvalidKeysError: Shortage: [:b] / Excess: []>
20
- my_obj.my_method(a: 1, b: 2) #=> "{:a=>1, :b=>2} is valid"
21
- my_obj.my_method(a: 1, b: 2, c: 3, d: 4) #=> #<KeyValidatable::InvalidKeysError: Shortage: [] / Excess: [:d]>
@@ -1,30 +0,0 @@
1
- # coding: us-ascii
2
-
3
- lib_name = 'keyvalidatable'.freeze
4
-
5
- Gem::Specification.new do |gem|
6
- gem.authors = ['Kenichi Kamiya']
7
- gem.email = ['kachick1+ruby@gmail.com']
8
- gem.description = %q{Validate shortage/excess keys in pairs.}
9
- gem.summary = gem.description.dup
10
- gem.homepage = "https://github.com/kachick/#{lib_name}"
11
- gem.license = 'MIT'
12
- gem.name = lib_name.dup
13
- gem.version = '0.1.0'
14
-
15
- gem.required_ruby_version = '>= 2.2'
16
-
17
- gem.add_development_dependency 'yard', '>= 0.9.11', '< 2.0'
18
- gem.add_development_dependency 'rake', '>= 10', '< 20'
19
- gem.add_development_dependency 'bundler', '>= 1.10', '< 2'
20
- gem.add_development_dependency 'declare', '~> 0.0.6'
21
-
22
- # common
23
-
24
- gem.authors = ['Kenichi Kamiya']
25
- gem.email = ['kachick1+ruby@gmail.com']
26
- gem.files = `git ls-files`.split($\)
27
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
28
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
29
- gem.require_paths = ['lib']
30
- end
@@ -1,15 +0,0 @@
1
- # coding: us-ascii
2
-
3
- require_relative '../keyvalidatable'
4
-
5
- class Hash
6
-
7
- include KeyValidatable
8
-
9
- end
10
-
11
- class Struct
12
-
13
- include KeyValidatable
14
-
15
- end
data/test/helper.rb DELETED
@@ -1,7 +0,0 @@
1
- # coding: us-ascii
2
-
3
- require 'declare/autorun'
4
-
5
- $VERBOSE = true
6
-
7
- require_relative '../lib/keyvalidatable'
@@ -1,42 +0,0 @@
1
- # coding: us-ascii
2
-
3
- require_relative '../lib/keyvalidatable'
4
- require_relative 'helper'
5
-
6
-
7
- requirements = {must: [:a, :c], let: [:b]}
8
-
9
- The(KeyValidatable.valid_array?([:a, :b, :c], requirements)) do
10
- same true
11
- end
12
-
13
- The([:a, :c]) do |sufficient|
14
- The(KeyValidatable.valid_array?(sufficient, requirements)) do
15
- same true
16
- end
17
-
18
- The(KeyValidatable.validate_array(sufficient, requirements)) do
19
- same nil
20
- end
21
- end
22
-
23
- The([:a, :b]) do |shortage|
24
- The(KeyValidatable.valid_array?(shortage, requirements)) do
25
- same false
26
- end
27
-
28
- CATCH KeyValidatable::InvalidKeysError do
29
- KeyValidatable.validate_array(shortage, requirements)
30
- end
31
- end
32
-
33
-
34
- The([:a, :b, :c, :d]) do |excess|
35
- The(KeyValidatable.valid_array?(excess, requirements)) do
36
- same false
37
- end
38
-
39
- CATCH KeyValidatable::InvalidKeysError do
40
- KeyValidatable.validate_array(excess, requirements)
41
- end
42
- end
@@ -1,53 +0,0 @@
1
- # coding: us-ascii
2
-
3
- require_relative 'helper'
4
- require_relative '../lib/keyvalidatable/core_ext'
5
-
6
- requirements = {must: [:a, :c], let: [:b]}
7
-
8
- The({a: nil, b: nil, c: nil}.valid_keys?(requirements)) do
9
- same true
10
-
11
- end
12
-
13
- The({a: nil, c: nil}) do |sufficient|
14
- The sufficient.valid_keys?(requirements) do
15
- same true
16
- end
17
-
18
- The sufficient.validate_keys(requirements) do
19
- same nil
20
- end
21
-
22
- The KeyValidatable.keys_for(sufficient) do
23
- is [:a, :c]
24
- end
25
- end
26
-
27
- The({a: nil, b: nil}) do |shortage|
28
- The shortage.valid_keys?(requirements) do
29
- same false
30
- end
31
-
32
- CATCH KeyValidatable::InvalidKeysError do
33
- shortage.validate_keys(requirements)
34
- end
35
-
36
- The KeyValidatable.keys_for(shortage) do
37
- is [:a, :b]
38
- end
39
- end
40
-
41
- The({a: nil, b: nil, c: nil, d: nil}) do |excess|
42
- The excess.valid_keys?(requirements) do
43
- same false
44
- end
45
-
46
- CATCH KeyValidatable::InvalidKeysError do
47
- excess.validate_keys(requirements)
48
- end
49
-
50
- The KeyValidatable.keys_for(excess) do
51
- is [:a, :b, :c, :d]
52
- end
53
- end
@@ -1,52 +0,0 @@
1
- # coding: us-ascii
2
-
3
- require_relative 'helper'
4
- require_relative '../lib/keyvalidatable/core_ext'
5
-
6
- requirements = {must: [:a, :c], let: [:b]}
7
-
8
- The(Struct.new(:a, :b, :c).new.valid_keys?(requirements)) do
9
- same true
10
- end
11
-
12
- The(Struct.new(:a, :c).new) do |sufficient|
13
- The sufficient.valid_keys?(requirements) do
14
- same true
15
- end
16
-
17
- The sufficient.validate_keys(requirements) do
18
- same nil
19
- end
20
-
21
- The KeyValidatable.keys_for(sufficient) do
22
- is [:a, :c]
23
- end
24
- end
25
-
26
- The(Struct.new(:a, :b).new) do |shortage|
27
- The shortage.valid_keys?(requirements) do
28
- same false
29
- end
30
-
31
- CATCH KeyValidatable::InvalidKeysError do
32
- shortage.validate_keys(requirements)
33
- end
34
-
35
- The KeyValidatable.keys_for(shortage) do
36
- is [:a, :b]
37
- end
38
- end
39
-
40
- The(Struct.new(:a, :b, :c, :d).new) do |excess|
41
- The excess.valid_keys?(requirements) do
42
- same false
43
- end
44
-
45
- CATCH KeyValidatable::InvalidKeysError do
46
- excess.validate_keys(requirements)
47
- end
48
-
49
- The KeyValidatable.keys_for(excess) do
50
- is [:a, :b, :c, :d]
51
- end
52
- end
@@ -1,51 +0,0 @@
1
- # coding: us-ascii
2
-
3
- require_relative 'helper'
4
- require_relative '../lib/keyvalidatable/core_ext'
5
-
6
-
7
- requirements = {let: [:b]}
8
-
9
- The({a: nil, b: nil, c: nil}.valid_keys?(requirements)) do
10
- same false
11
- end
12
-
13
- The({b: nil}) do |sufficient|
14
- The sufficient.valid_keys?(requirements) do
15
- same true
16
- end
17
-
18
- The sufficient.validate_keys(requirements) do
19
- same nil
20
- end
21
- end
22
-
23
- The({}) do |empty|
24
- The empty.valid_keys?(requirements) do
25
- same true
26
- end
27
-
28
- The empty.validate_keys(requirements) do
29
- same nil
30
- end
31
- end
32
-
33
- The({a: nil}) do |shortage|
34
- The shortage.valid_keys?(requirements) do
35
- same false
36
- end
37
-
38
- CATCH KeyValidatable::InvalidKeysError do
39
- shortage.validate_keys(requirements)
40
- end
41
- end
42
-
43
- The({a: nil, b: nil}) do |excess|
44
- The excess.valid_keys?(requirements) do
45
- same false
46
- end
47
-
48
- CATCH KeyValidatable::InvalidKeysError do
49
- excess.validate_keys(requirements)
50
- end
51
- end
@@ -1,40 +0,0 @@
1
- # coding: us-ascii
2
-
3
- require_relative 'helper'
4
- require_relative '../lib/keyvalidatable/core_ext'
5
-
6
- requirements = {let: [:b]}
7
-
8
- The(Struct.new(:a, :b, :c).new.valid_keys?(requirements)) do
9
- same false
10
- end
11
-
12
- The(Struct.new(:b).new) do |sufficient|
13
- The sufficient.valid_keys?(requirements) do
14
- same true
15
- end
16
-
17
- The sufficient.validate_keys(requirements) do
18
- same nil
19
- end
20
- end
21
-
22
- The(Struct.new(:a).new) do |shortage|
23
- The shortage.valid_keys?(requirements) do
24
- same false
25
- end
26
-
27
- CATCH KeyValidatable::InvalidKeysError do
28
- shortage.validate_keys(requirements)
29
- end
30
- end
31
-
32
- The(Struct.new(:a, :b).new) do |excess|
33
- The excess.valid_keys?(requirements) do
34
- same false
35
- end
36
-
37
- CATCH KeyValidatable::InvalidKeysError do
38
- excess.validate_keys(requirements)
39
- end
40
- end