This MR adds the possibility to define a custom context object to pass to the initializer of the Serializer.
This change also allows the context to be available in nested one or many association blocks inside the serializer definition.
So now you can do
class ProductSerializer < Barley::Serializer
attribute :name do
object.localized_name(context.locale)
end
many :storages do
many :shelves do
object.localized_name(context.locale) # context is available here too!
end
end
end
Type of change
Please delete options that are not relevant.
[x] New feature (non-breaking change which adds functionality)
[x] This change requires a documentation update
How Has This Been Tested?
[x] updated the serializer_test.rb file with relevant tests
Benchmarks
Barley is fast, and should be kept as fast as possible. Provide benchmarks related to speed and memory footprint.
Checklist:
[x] My code follows the style guidelines of this project
[x] I have performed a self-review of my code
[x] I have commented my code, particularly in hard-to-understand areas
[x] I have made corresponding changes to the documentation
[x] My changes generate no new warnings
[x] I have added tests that prove my fix is effective or that my feature works
[x] New and existing tests pass locally with my changes
Description
This MR adds the possibility to define a custom
context
object to pass to the initializer of theSerializer
.This change also allows the context to be available in nested
one
ormany
association blocks inside the serializer definition.So now you can do
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
serializer_test.rb
file with relevant testsBenchmarks
Barley is fast, and should be kept as fast as possible. Provide benchmarks related to speed and memory footprint.
Checklist: