README.md in json-serializer-0.0.9 vs README.md in json-serializer-1.0.0
- old
+ new
@@ -1,24 +1,34 @@
-json-serializer
+json-serializer [![Build Status](https://travis-ci.org/frodsan/json-serializer.svg)](https://travis-ci.org/frodsan/json-serializer)
===============
Customizes JSON output through serializer objects.
-A minimal implementation of [active_model_serializers][active_model_serializers] gem.
-
Installation
------------
+Add this line to your application's Gemfile:
+
+```ruby
+gem "json-serializer"
```
-gem install json-serializer
+
+And then execute:
+
```
+$ bundle
+```
+Or install it yourself as:
+
+```
+$ gem install json-serializer
+```
+
Usage
-----
-### Basics
-
Here's a simple example:
```ruby
require "json_serializer"
@@ -46,11 +56,12 @@
UserSerializer.new(user).to_json(root: :user)
# => "{\"user\":{\"id\":1,\"first_name\":\"Sonny\",\"last_name\":\"Moore\"}}"
```
-### Arrays
+Arrays
+------
A serializer can be used for objects contained in an array:
```ruby
require "json_serializer"
@@ -75,11 +86,12 @@
{ "id": 1, "title": "Post 1", "body": "Hello!" },
{ "id": 2, "title": "Post 2", "body": "Goodbye!" }
]
```
-### Attributes
+Attributes
+----------
By default, before looking up the attribute on the object, it checks the presence
of a method with the name of the attribute. This allow serializes to include
properties in addition to the object attributes or customize the result of a
specified attribute. You can access the object being serialized with the +object+
@@ -114,11 +126,11 @@
class UserSerializer < JsonSerializer
attribute :id
attribute :first_name
attribute :last_name
- attr :current_user
+ attr_reader :current_user
def initialize(object, current_user)
super(object)
@current_user = current_user
end
@@ -129,11 +141,12 @@
hash
end
end
```
-### Attributes with Custom Serializer
+Attributes with Custom Serializer
+---------------------------------
You can specify a serializer class for a defined attribute. This is very useful
for serializing each element of an association.
```ruby
@@ -190,6 +203,36 @@
}
]
}
```
+Contributing
+------------
+
+Fork the project with:
+
+```
+$ git clone git@github.com:frodsan/json-serializer.git
+```
+
+To install dependencies, use:
+
+```
+$ bundle install
+```
+
+To run the test suite, do:
+
+```
+$ rake test
+```
+
+For bug reports and pull requests use [GitHub][issues].
+
+License
+-------
+
+This gem is released under the [MIT License][mit].
+
[active_model_serializers]: https://github.com/rails-api/active_model_serializers
+[mit]: http://www.opensource.org/licenses/MIT
+[issues]: https://github.com/frodsan/json-serializer/issues