Sha256: 41e188e4760cf4c3cd9a92ae09290d694ec6d593768ca6c1363e3564c0a0bcd9

Contents?: true

Size: 707 Bytes

Versions: 7

Compression:

Stored size: 707 Bytes

Contents

require 'active_model/serializable'

module ActiveModel
  # DefaultSerializer
  #
  # Provides a constant interface for all items
  class DefaultSerializer
    include ActiveModel::Serializable

    attr_reader :object

    def initialize(object, options={})
      @object = object
      @wrap_in_array = options[:_wrap_in_array]
    end

    def as_json(options={})
      instrument('!serialize') do
        return [] if @object.nil? && @wrap_in_array
        hash = @object.as_json
        @wrap_in_array ? [hash] : hash
      end
    end
    alias serializable_hash as_json
    alias serializable_object as_json

    private
    def instrumentation_keys
      [:object, :wrap_in_array]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
active_model_serializers-0.9.6 lib/active_model/default_serializer.rb
active_model_serializers-0.9.5 lib/active_model/default_serializer.rb
active_model_serializers-0.9.4 lib/active_model/default_serializer.rb
active_model_serializers-0.9.3 lib/active_model/default_serializer.rb
active_model_serializers-0.9.2 lib/active_model/default_serializer.rb
active_model_serializers-0.9.1 lib/active_model/default_serializer.rb
active_model_serializers-0.9.0 lib/active_model/default_serializer.rb