mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
PR comments
- Add list of breaking changes - Add `true` param to `responds_to?` calls in overriden `try`
This commit is contained in:
parent
3ecc3ed0c1
commit
e966d07b2c
@ -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
|
new serializers that don't use these backwards compatible versions and slowly migrate
|
||||||
existing serializers to the `0.10` versions as needed.
|
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
|
## Steps to migrate
|
||||||
|
|
||||||
### 1. Upgrade the `active_model_serializer` gem in you `Gemfile`
|
### 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`,
|
# Since attributes could be read from the `object` via `method_missing`,
|
||||||
# the `try` method did not behave as before. This patches `try` with the
|
# the `try` method did not behave as before. This patches `try` with the
|
||||||
# original implementation plus the addition of
|
# 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.
|
# the given method.
|
||||||
def try(*a, &b)
|
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)
|
try!(*a, &b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user