README.md in supa-0.1.4 vs README.md in supa-0.2.0
- old
+ new
@@ -1,13 +1,13 @@
# Supa
Ruby object → JSON serialization.
-[](https://travis-ci.org/dasnotme/supa)
-[](https://codeclimate.com/github/dasnotme/supa)
-[](https://codeclimate.com/github/dasnotme/supa/coverage)
-[](https://codeclimate.com/github/dasnotme/supa)
+[](https://travis-ci.org/distribusion/supa)
+[](https://codeclimate.com/repos/587387071c36ea7203000e0d/feed)
+[](https://codeclimate.com/repos/587387071c36ea7203000e0d/coverage)
+[](https://codeclimate.com/repos/587387071c36ea7203000e0d/feed)
## Introduction
## Installation
@@ -81,21 +81,21 @@
end
end
end
end
- polymorphic :included, getter: proc { [self.author] } do
+ collection :included, getter: proc { [self.author] } do
attribute :id
attribute :type, getter: proc { 'authors' }
namespace :attributes do
attribute :first_name
attribute :last_name
end
end
- polymorphic :included, getter: proc { self.comments } do
+ collection :included, getter: proc { self.comments }, squash: true do
attribute :id
attribute :type, getter: proc { 'comments' }
namespace :attributes do
attribute :text
@@ -175,12 +175,57 @@
### `object`
### `collection`
-### `polymorphic`
+#### `:squash` option
+Passing `true` to `:squash` option results in merging collection with the previous one
+
+```ruby
+class AnimalsRepresenter
+ include Supa::Representable
+
+ define do
+ collection :animals, getter: -> { [{name: 'Rex', type: 'dogs'}] } do
+ attribute :name
+ attribute :type
+ end
+
+ collection :animals, getter: -> { [{name: 'Tom', type: 'cats'}] }, squash: true do
+ attribute :name
+ attribute :type
+ end
+ end
+end
+```
+
+```ruby
+ AnimalsRepresenter.new(nil).to_hash
+```
+
+```ruby
+{
+ animals: [
+ {name: 'Rex', type: 'dogs'},
+ {name: 'Tom', type: 'cats'}
+ ]
+}
+```
+
+### `:getter` option
+
+Avoid passing Proc objects to `:getter` option because this is little slower than method name passing
+
+```ruby
+# Bad
+attribute :name, getter: -> { fetch_name }
+
+# Good
+attribute :name, getter: :fetch_name
+```
+
## Development
To install dependencies
```shell
bin/setup
@@ -201,12 +246,11 @@
bin/console
```
## Contributing
-Bug reports and pull requests are welcome on GitHub at https://github.com/dasnotme/supa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
+Bug reports and pull requests are welcome on GitHub at https://github.com/distribusion/supa.
+This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
-
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
-