rschema 1.1.1 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 680986a4beef5eb8c444a63a116b9452de73f0c5
4
- data.tar.gz: d010e1a72333f9e30476dd610c93397ee4f4a4f0
3
+ metadata.gz: 29be05f4beeb1a5f7113f78d3080284a60ff08b5
4
+ data.tar.gz: f4bc95c00632d5133ce9e78c90cf8b599b4a4cd5
5
5
  SHA512:
6
- metadata.gz: c81e8ced5fc9fc7d5c710f9c05efda1ec02329e7f74b73176e89d9426f935d54bb94f985f6ad831dd65ec18aa8977f5cf429764dc012eb3db6bab55cacfea999
7
- data.tar.gz: 51eb121432f8734d32333f67d6e9e5c57103cf994401c276c58ac237f2c9923dd1469bbb9c20b0069f9aa609736ba2cadbc5cfbb7074d9b27ed96ddb1a25d25a
6
+ metadata.gz: 3711949f194d8fd3f2791c83ca71cf5d9dc11618af52aa3d9168fa65899db48d40849201ebede66992775b5db2c7dfb730864501a114c2b2e9cd528d91259d96
7
+ data.tar.gz: a7c3f7815d70423d3ed6c98841f1473607350d26798f313d02eb1dece212a1cf6cc6172878b46c18e1598ec72748cf08e1caa94bf1cefaef4d98ab35e0e7c4bd
data/README.md CHANGED
@@ -12,7 +12,7 @@ Schemas are generally just plain old hashes, arrays, and classes.
12
12
  ```ruby
13
13
  post_schema = {
14
14
  title: String,
15
- tags: [Symbol],
15
+ tags: Array[Symbol],
16
16
  body: String
17
17
  }
18
18
  ```
@@ -43,7 +43,7 @@ Then there are composite schemas, which are schemas composed of subschemas.
43
43
  Arrays are composite schemas:
44
44
 
45
45
  ```ruby
46
- schema = [Integer]
46
+ schema = Array[Integer]
47
47
  RSchema.validate(schema, [10, 11, 12]) #=> true
48
48
  RSchema.validate(schema, [10, 11, '12']) #=> false
49
49
  ```
@@ -84,12 +84,10 @@ are failing validation.
84
84
 
85
85
  ```ruby
86
86
  schema = RSchema.schema do
87
- [
88
- {
89
- name: String,
90
- hair: enum([:red, :brown, :blonde, :black])
91
- }
92
- ]
87
+ Array[{
88
+ name: String,
89
+ hair: enum([:red, :brown, :blonde, :black])
90
+ }]
93
91
  end
94
92
 
95
93
  value = [
@@ -136,7 +134,7 @@ There are two types of array schemas. When the array schema has a single
136
134
  element, it is a variable-length array schema:
137
135
 
138
136
  ```ruby
139
- schema = [Symbol]
137
+ schema = Array[Symbol]
140
138
  RSchema.validate(schema, [:a, :b, :c]) #=> true
141
139
  RSchema.validate(schema, [:a]) #=> true
142
140
  RSchema.validate(schema, []) #=> true
@@ -145,7 +143,7 @@ RSchema.validate(schema, []) #=> true
145
143
  Otherwise, it is a fixed-length array schema
146
144
 
147
145
  ```ruby
148
- schema = [Integer, String]
146
+ schema = Array[Integer, String]
149
147
  RSchema.validate(schema, [10, 'hello']) #=> true
150
148
  RSchema.validate(schema, [10, 'hello', 'world']) #=> false
151
149
  RSchema.validate(schema, [10]) #=> false
@@ -166,7 +164,7 @@ Keys can be optional:
166
164
  ```ruby
167
165
  schema = RSchema.schema {{
168
166
  :fname => String,
169
- _?(:age) => Integer
167
+ optional(:age) => Integer
170
168
  }}
171
169
  RSchema.validate(schema, { fname: 'Lucy', age: 21 }) #=> true
172
170
  RSchema.validate(schema, { fname: 'Tom' }) #=> true
@@ -191,11 +189,18 @@ RSchema provides a few other schema types through its DSL:
191
189
  # boolean
192
190
  boolean_schema = RSchema.schema{ boolean }
193
191
  RSchema.validate(boolean_schema, false) #=> true
194
- RSchema.validate(boolean_schema, nil) #=> false
192
+ RSchema.validate(boolean_schema, nil) #=> false
193
+
194
+ # any
195
+ any_schema = RSchema.schema{ any }
196
+ RSchema.validate(any_schema, "Hi") #=> true
197
+ RSchema.validate(any_schema, true) #=> true
198
+ RSchema.validate(any_schema, false) #=> true
199
+ RSchema.validate(any_schema, nil) #=> true
195
200
 
196
201
  # maybe
197
202
  maybe_schema = RSchema.schema{ maybe(Integer) }
198
- RSchema.validate(maybe_schema, 5) #=> true
203
+ RSchema.validate(maybe_schema, 5) #=> true
199
204
  RSchema.validate(maybe_schema, nil) #=> true
200
205
 
201
206
  # enum
data/lib/rschema.rb CHANGED
@@ -70,9 +70,10 @@ module RSchema
70
70
 
71
71
  module DSL
72
72
  module Base
73
- def _?(key)
73
+ def optional(key)
74
74
  OptionalHashKey.new(key)
75
75
  end
76
+ alias_method :_?, :optional
76
77
 
77
78
  def hash_of(subschemas_hash)
78
79
  raise InvalidSchemaError unless subschemas_hash.size == 1
@@ -101,6 +102,10 @@ module RSchema
101
102
  def boolean
102
103
  BooleanSchema
103
104
  end
105
+
106
+ def any
107
+ AnySchema
108
+ end
104
109
  end
105
110
  extend Base
106
111
  end
@@ -239,6 +244,12 @@ module RSchema
239
244
  end
240
245
  end
241
246
  end
247
+
248
+ module AnySchema
249
+ def self.schema_walk(value, mapper)
250
+ value
251
+ end
252
+ end
242
253
  end
243
254
 
244
255
  class Class
@@ -1,3 +1,3 @@
1
1
  module RSchema
2
- VERSION = '1.1.1'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rschema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Dalling
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec