Skip to content

Commit 0e7cae4

Browse files
committed
pass context to ArraySerializer
1 parent 69aff2a commit 0e7cae4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/active_model/array_serializer.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ def initialize(object, options={})
1515
@object = object
1616
@scope = options[:scope]
1717
@root = options.fetch(:root, self.class._root)
18-
@polymorphic = options.fetch(:polymorphic, false)
18+
@polymorphic = options.fetch(:polymorphic, false)
1919
@meta_key = options[:meta_key] || :meta
2020
@meta = options[@meta_key]
2121
@each_serializer = options[:each_serializer]
2222
@resource_name = options[:resource_name]
2323
@only = options[:only] ? Array(options[:only]) : nil
2424
@except = options[:except] ? Array(options[:except]) : nil
25+
@context = options[:context]
2526
@namespace = options[:namespace]
2627
@key_format = options[:key_format] || options[:each_serializer].try(:key_format)
2728
end
28-
attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format
29+
attr_accessor :object, :scope, :root, :meta_key, :meta, :key_format, :context
2930

3031
def json_key
3132
key = root.nil? ? @resource_name : root
@@ -35,7 +36,7 @@ def json_key
3536

3637
def serializer_for(item)
3738
serializer_class = @each_serializer || Serializer.serializer_for(item, namespace: @namespace) || DefaultSerializer
38-
serializer_class.new(item, scope: scope, key_format: key_format, only: @only, except: @except, polymorphic: @polymorphic, namespace: @namespace)
39+
serializer_class.new(item, scope: scope, key_format: key_format, context: @context, only: @only, except: @except, polymorphic: @polymorphic, namespace: @namespace)
3940
end
4041

4142
def serializable_object(options={})
@@ -66,7 +67,7 @@ def embedded_in_root_associations
6667
private
6768

6869
def instrumentation_keys
69-
[:object, :scope, :root, :meta_key, :meta, :each_serializer, :resource_name, :key_format]
70+
[:object, :scope, :root, :meta_key, :meta, :each_serializer, :resource_name, :key_format, :context]
7071
end
7172
end
7273
end

0 commit comments

Comments
 (0)