Sha256: 53585c2e8bdc5793e6593033c341222a56d2d05d87e1663fbcd75e5c2cf11cc3

Contents?: true

Size: 621 Bytes

Versions: 1

Compression:

Stored size: 621 Bytes

Contents

# encoding: utf-8

require 'dm-core'
require 'dm-types/support/dirty_minder'

module DataMapper
  class Property
    class PgJSON < Object
      def dump(value)
        case value
        when ::NilClass, ::String
          value
        when ::Hash, ::Array
          Oj.dump(value, mode: :compat)
        else
          '{}'
        end
      end

      def load(value)
        case value
        when ::Hash, ::Array
          value
        when ::String
          Oj.load(value)
        else
          {}
        end
      end

      def primitive?(value)
        value.kind_of?(::String)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-pg-json-0.2.0 lib/dm-pg-json/property/pgjson.rb