Sha256: 1560fec9d2db84e6a7697585ca671c5f0e1a52c1a22f6b56eb641cf6d4aede4b

Contents?: true

Size: 758 Bytes

Versions: 5

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true

module CycloneLariat
  module Repo
    module Mappers
      class Base
        class << self
          private

          def hash_from_json_column(data)
            return data if data.is_a?(Hash)
            return JSON.parse(data) if data.is_a?(String)

            if pg_json_extension_enabled?
              return data.to_h             if data.is_a?(::Sequel::Postgres::JSONHash)
              return JSON.parse(data.to_s) if data.is_a?(::Sequel::Postgres::JSONString)
            end

            raise ArgumentError, "Unknown type of `#{data}`"
          end

          def pg_json_extension_enabled?
            Object.const_defined?('Sequel::Postgres::JSONHash')
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cyclone_lariat-1.0.0 lib/cyclone_lariat/repo/mappers/base.rb
cyclone_lariat-1.0.0.rc9 lib/cyclone_lariat/repo/mappers/base.rb
cyclone_lariat-1.0.0.rc8 lib/cyclone_lariat/repo/mappers/base.rb
cyclone_lariat-1.0.0.rc7 lib/cyclone_lariat/repo/mappers/base.rb
cyclone_lariat-1.0.0.rc6 lib/cyclone_lariat/repo/mappers/base.rb