Makes passed in options accessible inside serializers

In some cases, we want to pass arguments from the controller and we want
to serializer a resource according to that. This allows serializers to
use the `options` method to retrieve whatever was passed in via
arguments.
This commit is contained in:
Alexandre de Oliveira
2015-03-11 14:53:57 -03:00
parent b8df4b57a1
commit 48650ecf7e
3 changed files with 28 additions and 0 deletions

View File

@@ -140,6 +140,7 @@ module ActiveModel
def initialize(object, options = {})
@object = object
@options = options
@root = options[:root] || (self.class._root ? self.class.root_name : false)
@meta = options[:meta]
@meta_key = options[:meta_key]
@@ -201,6 +202,8 @@ module ActiveModel
private
attr_reader :options
def self.get_serializer_for(klass)
serializer_class_name = "#{klass.name}Serializer"
serializer_class = serializer_class_name.safe_constantize