respect 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -11
- data/RELEASE_NOTES.md +5 -2
- data/lib/respect/version.rb +1 -1
- data/test/test_helper.rb +5 -2
- metadata +5 -5
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Welcome to Respect
|
2
2
|
|
3
|
-
_Respect_ is a DSL to concisely describe the structure of common data such as
|
3
|
+
_Respect_ is a DSL to concisely describe the structure of common data such as hash and array using
|
4
4
|
Ruby code. It comes with a validator, a sanitizer and dumpers to generate valid
|
5
5
|
[json-schema.org](http://json-schema.org/) compliant specifications. Although it was designed to
|
6
6
|
specify JSON schema, it can be used for any data represented as Hash and Array. It does not require
|
@@ -33,7 +33,7 @@ Thus, it is ideal to specify JSON schema. I find it a way more concise than
|
|
33
33
|
[json-schema.org](http://json-schema.org/). And it is plain Ruby so you can rely on all great Ruby features
|
34
34
|
to factor your specification code.
|
35
35
|
|
36
|
-
For instance, this ruby code
|
36
|
+
For instance, this ruby code specifies how one could structure a very simple user profile:
|
37
37
|
|
38
38
|
```ruby
|
39
39
|
schema = Respect::HashSchema.define do |s|
|
@@ -101,7 +101,7 @@ _Respect_ does not parse JSON document by default but it is easy to do so using
|
|
101
101
|
schema.validate?(JSON.parse('{ "name": "My name", "age": 20, "email": "me@example.com" }')) #=> true
|
102
102
|
```
|
103
103
|
|
104
|
-
Once a JSON document has been validated, we often want to turn its basic strings and integers into real
|
104
|
+
Once a JSON document has been validated, we often want to turn its basic strings and integers into real objects like `URI`.
|
105
105
|
_Respect_ does that automatically for you for standard objects:
|
106
106
|
|
107
107
|
```ruby
|
@@ -113,7 +113,7 @@ schema.validate!(object) #=> true
|
|
113
113
|
object["homepage"].class #=> URI::HTTP
|
114
114
|
```
|
115
115
|
|
116
|
-
You can easily extend the sanitizer with your own object type. Let's assume you have an object type
|
116
|
+
You can easily extend the sanitizer with your own object type. Let's assume you have an object type defined like this:
|
117
117
|
|
118
118
|
```ruby
|
119
119
|
class Place
|
@@ -129,7 +129,7 @@ class Place
|
|
129
129
|
end
|
130
130
|
```
|
131
131
|
|
132
|
-
Then you
|
132
|
+
Then you can extend the `Schema` class hierarchy with the new schema for your custom type.
|
133
133
|
The `CompositeSchema` class assists you in this task so you just have to overwrite
|
134
134
|
two methods.
|
135
135
|
|
@@ -188,12 +188,12 @@ end
|
|
188
188
|
```
|
189
189
|
|
190
190
|
In such case, you don't need a custom sanitizer. You just want to factor the definition of
|
191
|
-
identifier property. You can easily
|
191
|
+
identifier property. You can easily do it like this:
|
192
192
|
|
193
193
|
```ruby
|
194
194
|
module MyMacros
|
195
|
-
def id(name, options = {})
|
196
|
-
unless name.nil? || name =~ /_id$/
|
195
|
+
def id(name = "id", options = {})
|
196
|
+
unless name.nil? || name == "id" || name =~ /_id$/
|
197
197
|
name += "_id"
|
198
198
|
end
|
199
199
|
integer(name, { greater_than: 0 }.merge(options))
|
@@ -202,7 +202,7 @@ end
|
|
202
202
|
Respect.extend_dsl_with(MyMacros)
|
203
203
|
```
|
204
204
|
|
205
|
-
Now you can rewrite
|
205
|
+
Now you can rewrite your schema definition this way:
|
206
206
|
|
207
207
|
```ruby
|
208
208
|
Respect::HashSchema.define do |s|
|
@@ -247,7 +247,7 @@ Although, the semantics of the schema definition DSL available in this library m
|
|
247
247
|
_JSON schema standard_, we have tried to keep it as close as possible. For instance the `strict` option of
|
248
248
|
hash schema is not presented in the standard. However, when a schema is dumped to its _JSON Schema_ version
|
249
249
|
the syntax and semantic have been followed. You should note that there is no "loader" available yet in this
|
250
|
-
library. In other word, you cannot instantiate a Schema class from a _JSON Schema_ string representation.
|
250
|
+
library. In other word, you cannot instantiate a `Schema` class from a _JSON Schema_ string representation.
|
251
251
|
|
252
252
|
# Getting help
|
253
253
|
|
@@ -280,7 +280,7 @@ I would love to hear what you think about this library. Feel free to post any co
|
|
280
280
|
|
281
281
|
I spent quite a lot of time writing this gem but there is still a lot of work to do. Whether it
|
282
282
|
is a bug-fix, a new feature, some code re-factoring, or documentation clarification, I will be
|
283
|
-
glade to merge your pull
|
283
|
+
glade to merge your pull-request on GitHub. You just have to create a branch from `master` and
|
284
284
|
send me a pull request.
|
285
285
|
|
286
286
|
# License
|
data/RELEASE_NOTES.md
CHANGED
@@ -7,8 +7,11 @@ Note that each entry is kept so brief that no reason behind or
|
|
7
7
|
reference information is supplied with. For a full list of changes
|
8
8
|
with all sufficient information, see the git(1) log.
|
9
9
|
|
10
|
-
A lot more is coming soon check out the issue
|
11
|
-
|
10
|
+
A lot more is coming soon check out the issue tracker.
|
11
|
+
|
12
|
+
## Part of 0.1.1
|
13
|
+
|
14
|
+
* Fix: English mistakes in documentation and gemspec.
|
12
15
|
|
13
16
|
## Part of the first release
|
14
17
|
|
data/lib/respect/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -38,8 +38,11 @@ end
|
|
38
38
|
# A module to test statement extension helper.
|
39
39
|
module EndUserDSLStatement
|
40
40
|
|
41
|
-
def id(name = "id")
|
42
|
-
|
41
|
+
def id(name = "id", options = {})
|
42
|
+
unless name.nil? || name == "id" || name =~ /_id$/
|
43
|
+
name += "_id"
|
44
|
+
end
|
45
|
+
integer(name, { greater_than: 0 }.merge(options))
|
43
46
|
end
|
44
47
|
|
45
48
|
def call_to_kernel
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: respect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: 1.3.3
|
110
|
-
description: Respect
|
110
|
+
description: Respect lets you specify object schema using a Ruby DSL. It also provides
|
111
111
|
validators, sanitizers and dumpers to generate json-schema.org compliant spec. It
|
112
112
|
is perfect to specify JSON document structure.
|
113
113
|
email:
|
@@ -226,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
226
226
|
version: '0'
|
227
227
|
segments:
|
228
228
|
- 0
|
229
|
-
hash:
|
229
|
+
hash: -286809090323322661
|
230
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
231
231
|
none: false
|
232
232
|
requirements:
|
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
235
|
version: '0'
|
236
236
|
segments:
|
237
237
|
- 0
|
238
|
-
hash:
|
238
|
+
hash: -286809090323322661
|
239
239
|
requirements: []
|
240
240
|
rubyforge_project:
|
241
241
|
rubygems_version: 1.8.23
|