This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
17 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Welcome to Respect | ||
|
||
_Respect_ is a DSL to concisely describe the structure of common data such as Hash and Array using | ||
_Respect_ is a DSL to concisely describe the structure of common data such as hash and array using | ||
Ruby code. It comes with a validator, a sanitizer and dumpers to generate valid | ||
[json-schema.org](http://json-schema.org/) compliant specifications. Although it was designed to | ||
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 | |
[json-schema.org](http://json-schema.org/). And it is plain Ruby so you can rely on all great Ruby features | ||
to factor your specification code. | ||
|
||
For instance, this ruby code specify how one could structure a very simple user profile: | ||
For instance, this ruby code specifies how one could structure a very simple user profile: | ||
|
||
```ruby | ||
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 | |
schema.validate?(JSON.parse('{ "name": "My name", "age": 20, "email": "[email protected]" }')) #=> true | ||
``` | ||
|
||
Once a JSON document has been validated, we often want to turn its basic strings and integers into real object like `URI`. | ||
Once a JSON document has been validated, we often want to turn its basic strings and integers into real objects like `URI`. | ||
_Respect_ does that automatically for you for standard objects: | ||
|
||
```ruby | ||
|
@@ -113,7 +113,7 @@ schema.validate!(object) #=> true | |
object["homepage"].class #=> URI::HTTP | ||
``` | ||
|
||
You can easily extend the sanitizer with your own object type. Let's assume you have an object type define like this: | ||
You can easily extend the sanitizer with your own object type. Let's assume you have an object type defined like this: | ||
|
||
```ruby | ||
class Place | ||
|
@@ -129,7 +129,7 @@ class Place | |
end | ||
``` | ||
|
||
Then you must extend the Schema hierarchy with the new schema for your custom type. | ||
Then you can extend the `Schema` class hierarchy with the new schema for your custom type. | ||
The `CompositeSchema` class assists you in this task so you just have to overwrite | ||
two methods. | ||
|
||
|
@@ -188,12 +188,12 @@ end | |
``` | ||
|
||
In such case, you don't need a custom sanitizer. You just want to factor the definition of | ||
identifier property. You can easily to it like this: | ||
identifier property. You can easily do it like this: | ||
|
||
```ruby | ||
module MyMacros | ||
def id(name, options = {}) | ||
unless name.nil? || name =~ /_id$/ | ||
def id(name = "id", options = {}) | ||
unless name.nil? || name == "id" || name =~ /_id$/ | ||
name += "_id" | ||
end | ||
integer(name, { greater_than: 0 }.merge(options)) | ||
|
@@ -202,7 +202,7 @@ end | |
Respect.extend_dsl_with(MyMacros) | ||
``` | ||
|
||
Now you can rewrite the original schema this way: | ||
Now you can rewrite your schema definition this way: | ||
|
||
```ruby | ||
Respect::HashSchema.define do |s| | ||
|
@@ -247,7 +247,7 @@ Although, the semantics of the schema definition DSL available in this library m | |
_JSON schema standard_, we have tried to keep it as close as possible. For instance the `strict` option of | ||
hash schema is not presented in the standard. However, when a schema is dumped to its _JSON Schema_ version | ||
the syntax and semantic have been followed. You should note that there is no "loader" available yet in this | ||
library. In other word, you cannot instantiate a Schema class from a _JSON Schema_ string representation. | ||
library. In other word, you cannot instantiate a `Schema` class from a _JSON Schema_ string representation. | ||
|
||
# Getting help | ||
|
||
|
@@ -280,7 +280,7 @@ I would love to hear what you think about this library. Feel free to post any co | |
|
||
I spent quite a lot of time writing this gem but there is still a lot of work to do. Whether it | ||
is a bug-fix, a new feature, some code re-factoring, or documentation clarification, I will be | ||
glade to merge your pull request on GitHub. You just have to create a branch from `master` and | ||
glade to merge your pull-request on GitHub. You just have to create a branch from `master` and | ||
send me a pull request. | ||
|
||
# License | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s| | |
s.email = ["[email protected]"] | ||
s.homepage = "http://nicolasdespres.github.io/respect" | ||
s.summary = "Object schema definition using a Ruby DSL." | ||
s.description = "Respect let you specify object schema using a Ruby DSL. It also provides validators, sanitizers and dumpers to generate json-schema.org compliant spec. It is perfect to specify JSON document structure." | ||
s.description = "Respect lets you specify object schema using a Ruby DSL. It also provides validators, sanitizers and dumpers to generate json-schema.org compliant spec. It is perfect to specify JSON document structure." | ||
|
||
s.files = Dir["lib/**/*"] + [ | ||
"MIT-LICENSE", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters