PR comments

- Add list of breaking changes
- Add `true` param to `responds_to?` calls in overriden `try`
This commit is contained in:
bkoltai 2016-07-13 10:10:50 -07:00
parent 3ecc3ed0c1
commit e966d07b2c

View File

@ -21,6 +21,27 @@ functionality as you had with `AMS 0.8`. Then, you can continue to develop in yo
new serializers that don't use these backwards compatible versions and slowly migrate
existing serializers to the `0.10` versions as needed.
### Basic list `0.10` breaking changes
- Passing a serializer to `render json:` is no longer supported
- Ex. `render json: CustomerSerializer.new(customer)`
- Passing a nil resource to serializer now fails
- Ex. `CustomerSerializer.new(nil)`
- Attribute methods are no longer accessible from other serializer methods
- Ex.
```ruby
class MySerializer
attributes :foo, :bar
def foo
bar + 1
end
end
```
- `root` option to collection serializer behaves differently
- Ex. `ActiveModel::ArraySerializer.new(resources, root: "resources")`
- No default serializer when serializer doesn't exist
- `@options` changed to `instance_options`
## Steps to migrate
### 1. Upgrade the `active_model_serializer` gem in you `Gemfile`
@ -46,10 +67,10 @@ module ActiveModel
# Since attributes could be read from the `object` via `method_missing`,
# the `try` method did not behave as before. This patches `try` with the
# original implementation plus the addition of
# ` || object.respond_to?(a.first)` to check if the object responded to
# ` || object.respond_to?(a.first, true)` to check if the object responded to
# the given method.
def try(*a, &b)
if a.empty? || respond_to?(a.first) || object.respond_to?(a.first)
if a.empty? || respond_to?(a.first, true) || object.respond_to?(a.first, true)
try!(*a, &b)
end
end