Sha256: 583cec61a040dc2e215958c8f3ccc62ba03c51ed5478be666a6df93d77dada0c

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

module Traitorous
  module Converter
    # The Identity converter is used as a simple default which performs the
    # jobs of a Converter without changing the inputs at all.
    #
    # This converter can be used when you have simple data (strings, dates,
    #   numbers, hashes and arrays of the same) that doesn't need to be inflated
    #   into an object and needs no changes to be safely stored as the same.
    class Identity
      # do_export is called in order to take an existing piece of data and
      #   prepare it to be written to a simpler data structure.
      #
      # The Identity converter exports the same data it is passed without
      #   changing them at all.
      #
      # @params data [Object] the data object passed in to be exported
      # @return [Object] exports data to a form simple enough to save as JSON
      def do_export(data)
        data
      end

      # do_import is called in order to take some opts and to turn them into
      #   instantiated objects, arrays, or other types of transformation
      #
      # The Identity converter imports the same opts it is passed without
      #   changing them at all.
      #
      # @params opts [Object] the options to be imported
      # @return [Object] opts
      def do_import(opts)
        opts
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
traitorous-0.3.0 lib/traitorous/converter/identity.rb
traitorous-0.2.2 lib/traitorous/converter/identity.rb
traitorous-0.2.0 lib/traitorous/converter/identity.rb