README.md in schema_serializer-0.0.10 vs README.md in schema_serializer-0.1.0
- old
+ new
@@ -1,7 +1,10 @@
# SchemaSerializer
+[![Gem Version](https://badge.fury.io/rb/schema_serializer.svg)](https://badge.fury.io/rb/schema_serializer)
+[![Build Status](https://travis-ci.org/i2bskn/schema_serializer.svg?branch=master)](https://travis-ci.org/i2bskn/schema_serializer)
+
SchemaSerializer is provide serialization from schema definition to JSON.
## Installation
Add this line to your application's Gemfile:
@@ -10,35 +13,61 @@
gem "schema_serializer"
```
And then execute:
+```bash
+$ bundle install
```
-$ bundle
+
+Create config file(Only Rails) with:
+
+```bash
+$ bundle exec rails generate schema_serializer:install
```
+The following file will be created.
+
+- `config/initializers/schema_serializer.rb`
+- `doc/schema.yml`
+
## Usage
+### Create a serializer template with Rails Generator
+
+Create a serializer template in `app/serializers/user_serializer.rb`.
+
+```bash
+$ bundle exec rails g schema_serializer:serializer User
```
-SchemaSerializer.definition = {
- "User" => {
- "required" => ["id", "name"],
- "properties" => {
- "id" => {
- "type" => "integer",
- },
- "name" => {
- "type" => "string",
- },
- "age" => {
- "type" => "number",
- "nullable" => true,
- },
- }
- }
-}
-User.take.as_json
+### Serializer Definitions
+
+Serializer Definitions are describe in the `doc/schema.yml`.
+
+```yaml
+User:
+ required:
+ - id
+ - name
+ properties:
+ id:
+ type: integer
+ name:
+ type: string
+ age:
+ type: integer
+ nullable: true
+```
+
+### Serialization
+
+```ruby
+user = User.take
+SchemaSerializer.new(user).as_json.to_json
+
+# Only ActiveRecord Object
+user.serializer.as_json.to_json
```
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.