aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorbogdanvlviv <bogdanvlviv@gmail.com>2018-02-17 00:41:54 +0200
committerbogdanvlviv <bogdanvlviv@gmail.com>2018-02-17 17:48:10 +0200
commit30528cda9e30e42915f3a0fa204d822ce013c168 (patch)
treec4ea3e08f26bbca20d76b0be530eced4eb3c0bc5 /guides
parentd2c094aa5081677bf537a1553d0a756fcafcfb4e (diff)
downloadrails-30528cda9e30e42915f3a0fa204d822ce013c168.tar.gz
rails-30528cda9e30e42915f3a0fa204d822ce013c168.tar.bz2
rails-30528cda9e30e42915f3a0fa204d822ce013c168.zip
Fix docs of ActiveJob custom argument serializers
Add `:nodoc:` to `ActiveJob::Serializers` Add `:doc:` to `ActiveJob::Serializers::ObjectSerializer#klass` Express `ActiveJob::Serializers::ObjectSerializer#klass` as private method
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_job_basics.md27
1 files changed, 13 insertions, 14 deletions
diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md
index 9b738e8cdd..6db7ce370f 100644
--- a/guides/source/active_job_basics.md
+++ b/guides/source/active_job_basics.md
@@ -346,12 +346,12 @@ ActiveJob supports the following types of arguments by default:
- Basic types (`NilClass`, `String`, `Integer`, `Fixnum`, `Bignum`, `Float`, `BigDecimal`, `TrueClass`, `FalseClass`)
- `Symbol`
- - `ActiveSupport::Duration`
- `Date`
- `Time`
- `DateTime`
- `ActiveSupport::TimeWithZone`
- - `Hash`. Keys should be of `String` or `Symbol` type
+ - `ActiveSupport::Duration`
+ - `Hash` (Keys should be of `String` or `Symbol` type)
- `ActiveSupport::HashWithIndifferentAccess`
- `Array`
@@ -385,39 +385,38 @@ by default has been mixed into Active Record classes.
### Serializers
-You can extend list of supported types for arguments. You just need to define your own serializer.
+You can extend the list of supported argument types. You just need to define your own serializer:
```ruby
class MoneySerializer < ActiveJob::Serializers::ObjectSerializer
- # Check if this object should be serialized using this serializer.
+ # Checks if an argument should be serialized by this serializer.
def serialize?(argument)
argument.is_a? Money
end
- # Convert an object to a simpler representative using supported object types.
+ # Converts an object to a simpler representative using supported object types.
# The recommended representative is a Hash with a specific key. Keys can be of basic types only.
- # You should call `super` to add the custom serializer type to the hash
- def serialize(object)
+ # You should call `super` to add the custom serializer type to the hash.
+ def serialize(money)
super(
- "cents" => object.cents,
- "currency" => object.currency
+ "amount" => money.amount,
+ "currency" => money.currency
)
end
- # Convert serialized value into a proper object
+ # Converts serialized value into a proper object.
def deserialize(hash)
- Money.new hash["cents"], hash["currency"]
+ Money.new(hash["amount"], hash["currency"])
end
end
```
-And now you just need to add this serializer to a list:
+and add this serializer to the list:
```ruby
-Rails.application.config.active_job.custom_serializers << MySpecialSerializer
+Rails.application.config.active_job.custom_serializers << MoneySerializer
```
-
Exceptions
----------