objecheck 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +22 -0
- data/lib/objecheck/validator.rb +5 -1
- data/lib/objecheck/validator/respond_to_rule.rb +32 -0
- data/lib/objecheck/validator/satisfy_rule.rb +31 -0
- data/objecheck.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55f049c2873546da56fc94bf10b350e35e24840ecc47c48bffc3bb2aa1fd0f7a
|
4
|
+
data.tar.gz: e0d5a4f068debea5aa3a2deffa39b8e4b5235201ce199df201edd8aab5bd6a85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecb92185b82bbe07befc3999d23a835187260cbf8fd816e1ecfc210ab085394c4566fa9659eda045a9e4a40f25786f58135be45985833fedb103e3900481ea07
|
7
|
+
data.tar.gz: e8699e7ae61e3ef61deafc59c3b6ed9b4f15c908dc885677ab3a2e3d9f32d786112bbdd2fb0689766efcbd924f780dce5d06495222f900ef6a54eb714311aa11
|
data/CHANGELOG.md
CHANGED
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.
|
data/lib/objecheck/validator.rb
CHANGED
@@ -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
|
data/objecheck.gemspec
CHANGED
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.
|
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
|
+
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
|