README.md in rice_bubble-0.1.0 vs README.md in rice_bubble-0.1.1
- old
+ new
@@ -35,13 +35,15 @@
```
Then you can use the new serializer to convert your data to a JSON-friendly representation:
```ruby
-json = CharacterSerializer.call(my_character) # => { name: "...", ... }
+json = CharacterSerializer.new(my_character).call # => { name: "...", ... }
```
+**Note:** you can also use `CharacterSerializer.call(my_character)`.
+
### Attribute types
| Name | Expects | Options | Example |
| ------------ | -------------------------- | ---------------------------------------- | ------------------------------------------------ |
| `any` | any of the specified types | array of attribute types | `any(string, integer)` |
@@ -98,17 +100,30 @@
```
### Fetching values from an object
By default, attributes know how to fetch their values from the object being serialized
-by either:
+by either (in this order):
-- invoking an instance method (on an object); or
-- looking up a hash key (on a hash)
+- invoking an instance method with the same name on the serializer; or
+- invoking an instance method with the same name on the object; or
+- looking up a hash key on the object
-You can change how a value is retrieved by passing a block to the attribute:
+```ruby
+class FullNameSerializer
+ attributes(
+ full_name: string
+ )
+ def full_name
+ [object.first_name, object.last_name].join(' ')
+ end
+end
+```
+
+You can also change how a value is retrieved by passing a block to the attribute:
+
```ruby
class FullNameSerializer
attributes(
full_name: string { |o, _| [o.first_name, o.last_name].join(' ') }
)
@@ -132,6 +147,6 @@
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
-Everyone interacting in the RiceBubble project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rice_bubble/blob/main/CODE_OF_CONDUCT.md).
+Everyone interacting in the RiceBubble project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/fauxparse/rice_bubble/blob/main/CODE_OF_CONDUCT.md).