Sha256: ac9feb72fd1a4f61757556e38e200f2063983da6f8c2a2ca86f92922e68fd184

Contents?: true

Size: 834 Bytes

Versions: 4

Compression:

Stored size: 834 Bytes

Contents

module Findable
  class Query
    class Serializer
      def initialize(serializer = nil)
        @serializer = serializer || Findable.config.serializer
      end

      def serialize(object)
        @serializer.dump(object)
      end

      # @params raw_data [String] Serialized string
      # @params raw_data [Array<String>] Array of serialized string
      # @return [ActiveSupport::HashWithIndifferentAccess]
      # @return [Array<ActiveSupport::HashWithIndifferentAccess>]
      def deserialize(raw_data, klass = nil)
        objects = Array(raw_data).compact.map {|data|
          object = @serializer.load(data)
          object = object.with_indifferent_access if object.is_a?(Hash)
          klass ? klass.new(object) : object
        }
        raw_data.is_a?(String) ? objects.first : objects
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
findable-0.2.2 lib/findable/query/serializer.rb
findable-0.2.1 lib/findable/query/serializer.rb
findable-0.2.0 lib/findable/query/serializer.rb
findable-0.1.5 lib/findable/query/serializer.rb