objecheck 0.2.0 → 0.3.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: affc792d7a719592fb092a7e9c8bf3aa3bfbc06afca7fad8809ba1d053d1edbf
4
- data.tar.gz: d776e2cb69dcf8193f60f526bc07adec05aa8c27c80a4bb51c0d19ceba365f00
3
+ metadata.gz: 0e5e64af44a98f5a68b9a29c37c3aebb76b07838cab71bf1855b043f2e4c81f3
4
+ data.tar.gz: 1aab0ebbeb4d062fef6cfd2d89ae063ee9429864c11ed83f99523c053eeea677
5
5
  SHA512:
6
- metadata.gz: 5ccebbd3396d7f066cb2e7f6cb56c36de1e839d6ee12511e52128355b5e56708f614ed323fab8df3f9b48350d584eb486515376eb96cad4abe76bf9fd83258bf
7
- data.tar.gz: bbb8f479f54c1461e9b3c8a690d11fa86eaf6471a31d36c4d393312d47be60c14dfd29aa146791627eabc412a96a84cd4381a46172e0b57a779bdf2f091834d5
6
+ metadata.gz: 8b670597d9010ea8b5abb053f9e2a13f6c6c3b810e7b6b042421dc6a24ceee0b9de8607ba4bcb36e1f26c25fa015fae3e6146b900eab481fff703bae657f65db
7
+ data.tar.gz: e381afd9b7169b6bf6b38062df731bb4d9738fcbc483f25519c392acfb87e9e2b4da8f54598d189e29f378bfb798d9f5a922ae7ddceae836d0d18f6a93259042
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## v0.3.0
4
+
5
+ - Add `EqRule` as `eq`
6
+ - Enable `TypeRule` to check boolean (`true` or `false`)
7
+
3
8
  ## v0.2.0
4
9
 
5
10
  - Change signature of rule's `#validate` to enable nested schema
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.
@@ -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
- collector.add_error("should be a #{@type} (got #{target.class})") if !target.is_a?(@type)
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'objecheck'
3
- spec.version = '0.2.0'
3
+ spec.version = '0.3.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.2.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-20 00:00:00.000000000 Z
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