Sha256: adbf1d7c85bf2afbb73e1cc0795fd6c747528b79948f9af7f4b0251e330455d6

Contents?: true

Size: 571 Bytes

Versions: 2

Compression:

Stored size: 571 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=nil)
      @object = object
    end

    def as_json(options={})
      return nil if @object.nil?
      if @object.is_a?(Struct)
        Hash[@object.members.zip(@object.values)]
      else
        @object.as_json
      end
    end
    alias serializable_hash as_json
    alias serializable_object as_json
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_model_serializers_rails_2.3-0.9.0.alpha1 lib/active_model/default_serializer.rb
active_model_serializers_rails_2.3-0.9.0.pre2 lib/active_model/default_serializer.rb