Sha256: 4a0fbdad5001af593dbdbe6cd63e04b4b40dff996cc902b657d7d1e91c673e3d

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

module Chronicle
  module Serialization
    class Serializer
      # Construct a new instance of this serializer.
      # == Parameters:
      # options::
      #   Options for configuring this Serializers
      def initialize(record, options = {})
        unless record.is_a?(Chronicle::Serialization::Record)
          raise(ArgumentError,
            "Must be a Record. It is a: #{record.class}")
        end

        @record = record
        @options = options
      end

      # Serialize a record as a hash
      def serializable_hash
        raise NotImplementedError
      end

      def self.serialize(data)
        record = if data.is_a?(Chronicle::Models::Base)
                   Chronicle::Serialization::Record.build_from_model(data)
                 elsif data.is_a?(Chronicle::Serialization::Record)
                   data
                 else
                   raise ArgumentError, 'data must be a Chronicle::Models::Base or Chronicle::Serialization::Record'
                 end

        serializer = new(record)
        serializer.serializable_hash
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chronicle-core-0.3.2 lib/chronicle/serialization/serializer.rb
chronicle-core-0.3.1 lib/chronicle/serialization/serializer.rb
chronicle-core-0.3.0 lib/chronicle/serialization/serializer.rb