Class: RESTFramework::ActiveModelSerializerAdapterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/rest_framework/serializers.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



349
350
351
352
353
354
355
356
357
358
359
# File 'lib/rest_framework/serializers.rb', line 349

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