objecheck 0.5.0 → 0.6.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: 79e158220b8faff0033bfa2456ef1ac7bd10f4556261659f1217a052a2c42aef
4
- data.tar.gz: 2c45f51bc1cbb634e8027f78ec1c42b472e99c241a80f422abdcc09c8c9eb2c2
3
+ metadata.gz: 55f049c2873546da56fc94bf10b350e35e24840ecc47c48bffc3bb2aa1fd0f7a
4
+ data.tar.gz: e0d5a4f068debea5aa3a2deffa39b8e4b5235201ce199df201edd8aab5bd6a85
5
5
  SHA512:
6
- metadata.gz: 07f0b91db2957dbebdca3008c352750febb414ab96fb46dd37247a9799e43b3e3d8d9828fd063a3806372c7c29375f07bb8bad01c92d1806ace43ae1f125d3ab
7
- data.tar.gz: 6cc64f317e3ce3feaf859282c2db9317a81388e9b69e465c0b7123105c0d0bb9f252f08fbad9153b2a97e19fa789a465d6142c9f1cafa749d4316268b9e0cb3d
6
+ metadata.gz: ecb92185b82bbe07befc3999d23a835187260cbf8fd816e1ecfc210ab085394c4566fa9659eda045a9e4a40f25786f58135be45985833fedb103e3900481ea07
7
+ data.tar.gz: e8699e7ae61e3ef61deafc59c3b6ed9b4f15c908dc885677ab3a2e3d9f32d786112bbdd2fb0689766efcbd924f780dce5d06495222f900ef6a54eb714311aa11
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## v0.6.0
4
+
5
+ - Add `SatisfyRule` as `satisfy`
6
+ - Add `RespondToRule` as `respond_to`
7
+
3
8
  ## v0.5.0
4
9
 
5
10
  ### New features
data/README.md CHANGED
@@ -165,6 +165,28 @@ Example schema:
165
165
  }
166
166
  ```
167
167
 
168
+ ### `satisfy`
169
+
170
+ `satisfy` checks by Proc
171
+
172
+ Example schema:
173
+ ```ruby
174
+ {
175
+ satisfy: ->(x) { x.even? }
176
+ }
177
+ ```
178
+
179
+ ### `respond_to`
180
+
181
+ `respond_to` checks defined methods
182
+
183
+ Example schema:
184
+ ```ruby
185
+ {
186
+ respond_to: [:configure :run]
187
+ }
188
+ ```
189
+
168
190
  ## Contributing
169
191
 
170
192
  Bug reports and pull requests are welcome on GitHub at https://github.com/autopp/objecheck.
@@ -24,6 +24,8 @@ class Objecheck::Validator
24
24
  require 'objecheck/validator/key_value_rule'
25
25
  require 'objecheck/validator/eq_rule'
26
26
  require 'objecheck/validator/any_rule'
27
+ require 'objecheck/validator/satisfy_rule'
28
+ require 'objecheck/validator/respond_to_rule'
27
29
  DEFAULT_RULES = {
28
30
  type: TypeRule,
29
31
  each: EachRule,
@@ -31,7 +33,9 @@ class Objecheck::Validator
31
33
  each_value: EachValueRule,
32
34
  key_value: KeyValueRule,
33
35
  eq: EqRule,
34
- any: AnyRule
36
+ any: AnyRule,
37
+ satisfy: SatisfyRule,
38
+ respond_to: RespondToRule
35
39
  }.freeze
36
40
 
37
41
  def initialize(schema, rule_map = DEFAULT_RULES, schema_validation = true)
@@ -0,0 +1,32 @@
1
+ #
2
+ # Objecheck
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ # RespondToRule validates methods of object
18
+ #
19
+ class Objecheck::Validator::RespondToRule
20
+ def initialize(_validator, methods)
21
+ @methods = methods
22
+ end
23
+
24
+ def validate(target, collector)
25
+ not_responds = @methods.reject { |m| target.respond_to?(m) }
26
+ collector.add_error("should be respond to #{not_responds.join(', ')}") if !not_responds.empty?
27
+ end
28
+
29
+ def self.schema
30
+ [{ each: { type: Symbol } }]
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # Objecheck
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ # SatisfyRule validates objects by given Proc
18
+ #
19
+ class Objecheck::Validator::SatisfyRule
20
+ def initialize(_validator, pred)
21
+ @pred = pred
22
+ end
23
+
24
+ def validate(target, collector)
25
+ collector.add_error("should satisfy #{@pred.inspect}") if !@pred.call(target)
26
+ end
27
+
28
+ def self.schema
29
+ [{ respond_to: %i[call] }]
30
+ end
31
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'objecheck'
3
- spec.version = '0.5.0'
3
+ spec.version = '0.6.0'
4
4
  spec.authors = ['autopp']
5
5
  spec.email = ['autopp.inc@gmail.com']
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: objecheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - autopp
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-11 00:00:00.000000000 Z
11
+ date: 2018-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,8 @@ files:
94
94
  - lib/objecheck/validator/each_value_rule.rb
95
95
  - lib/objecheck/validator/eq_rule.rb
96
96
  - lib/objecheck/validator/key_value_rule.rb
97
+ - lib/objecheck/validator/respond_to_rule.rb
98
+ - lib/objecheck/validator/satisfy_rule.rb
97
99
  - lib/objecheck/validator/type_rule.rb
98
100
  - objecheck.gemspec
99
101
  homepage: https://github.com/autopp/objecheck