objecheck 0.2.0 → 0.3.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 +18 -0
- data/lib/objecheck/validator.rb +1 -0
- data/lib/objecheck/validator/eq_rule.rb +27 -0
- data/lib/objecheck/validator/type_rule.rb +5 -1
- data/objecheck.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e5e64af44a98f5a68b9a29c37c3aebb76b07838cab71bf1855b043f2e4c81f3
|
4
|
+
data.tar.gz: 1aab0ebbeb4d062fef6cfd2d89ae063ee9429864c11ed83f99523c053eeea677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b670597d9010ea8b5abb053f9e2a13f6c6c3b810e7b6b042421dc6a24ceee0b9de8607ba4bcb36e1f26c25fa015fae3e6146b900eab481fff703bae657f65db
|
7
|
+
data.tar.gz: e381afd9b7169b6bf6b38062df731bb4d9738fcbc483f25519c392acfb87e9e2b4da8f54598d189e29f378bfb798d9f5a922ae7ddceae836d0d18f6a93259042
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -75,6 +75,13 @@ Example schema:
|
|
75
75
|
}
|
76
76
|
```
|
77
77
|
|
78
|
+
When you want to check that value is a boolean (`true` or `false`), use `:bool`.
|
79
|
+
```ruby
|
80
|
+
{
|
81
|
+
type: :bool
|
82
|
+
}
|
83
|
+
```
|
84
|
+
|
78
85
|
### `each`
|
79
86
|
|
80
87
|
`each` checks elements of the object by using `each`.
|
@@ -133,6 +140,17 @@ Example schema:
|
|
133
140
|
}
|
134
141
|
```
|
135
142
|
|
143
|
+
### `eq`
|
144
|
+
|
145
|
+
`eq` checks equality of values.
|
146
|
+
|
147
|
+
Example schema:
|
148
|
+
```ruby
|
149
|
+
{
|
150
|
+
eq: 'foo'
|
151
|
+
}
|
152
|
+
```
|
153
|
+
|
136
154
|
## Contributing
|
137
155
|
|
138
156
|
Bug reports and pull requests are welcome on GitHub at https://github.com/autopp/objecheck.
|
data/lib/objecheck/validator.rb
CHANGED
@@ -22,6 +22,7 @@ class Objecheck::Validator
|
|
22
22
|
require 'objecheck/validator/each_key_rule'
|
23
23
|
require 'objecheck/validator/each_value_rule'
|
24
24
|
require 'objecheck/validator/key_value_rule'
|
25
|
+
require 'objecheck/validator/eq_rule'
|
25
26
|
DEFAULT_RULES = {
|
26
27
|
type: TypeRule,
|
27
28
|
each: EachRule,
|
@@ -0,0 +1,27 @@
|
|
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
|
+
# EqRule validates equality of objects
|
18
|
+
#
|
19
|
+
class Objecheck::Validator::EqRule
|
20
|
+
def initialize(_validator, value)
|
21
|
+
@value = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate(target, collector)
|
25
|
+
collector.add_error("should be equal to #{@value.inspect}") if @value != target
|
26
|
+
end
|
27
|
+
end
|
@@ -22,6 +22,10 @@ class Objecheck::Validator::TypeRule
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def validate(target, collector)
|
25
|
-
|
25
|
+
if @type == :bool
|
26
|
+
collector.add_error("should be a bool (got #{target.class})") if target != true && target != false
|
27
|
+
elsif !target.is_a?(@type)
|
28
|
+
collector.add_error("should be a #{@type} (got #{target.class})")
|
29
|
+
end
|
26
30
|
end
|
27
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.3.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-09-
|
11
|
+
date: 2018-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/objecheck/validator/each_key_rule.rb
|
91
91
|
- lib/objecheck/validator/each_rule.rb
|
92
92
|
- lib/objecheck/validator/each_value_rule.rb
|
93
|
+
- lib/objecheck/validator/eq_rule.rb
|
93
94
|
- lib/objecheck/validator/key_value_rule.rb
|
94
95
|
- lib/objecheck/validator/type_rule.rb
|
95
96
|
- objecheck.gemspec
|