Class: RESTFramework::Serializers::ActiveModelSerializerAdapterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_framework/serializers/active_model_serializer_adapter_factory.rb

Overview

This is a helper factory to wrap an ActiveModelSerializer to provide a ‘serialize` method which accepts both collections and individual records. Use `.for` to build adapters.

Class Method Summary collapse

Class Method Details

.for(active_model_serializer) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rest_framework/serializers/active_model_serializer_adapter_factory.rb', line 4

def self.for(active_model_serializer)
  return Class.new(active_model_serializer) do
    def serialize
      if self.object.respond_to?(:to_ary)
        return self.object.map { |r| self.class.superclass.new(r).serializable_hash }
      end

      return self.serializable_hash
    end
  end
end