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



288
289
290
291
292
293
294
295
296
297
298
# File 'lib/rest_framework/serializers.rb', line 288

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