Sha256: 8448eb830b073f0199fcf62e75334272645fb655c115af2ac43c448876ebddf0
Contents?: true
Size: 1.38 KB
Versions: 5
Compression:
Stored size: 1.38 KB
Contents
# frozen_string_literal: true module CycloneLariat module Repo class MessagesMapper class << self def from_row(row) return if row.nil? row[:data] = hash_from_json_column(row[:data]) row[:client_error_details] = hash_from_json_column(row[:client_error_details]) if row[:client_error_details] row end def to_row(input) { uuid: input.uuid, kind: input.kind, type: input.type, publisher: input.publisher, data: JSON.generate(input.data), client_error_message: input.client_error&.message, client_error_details: JSON.generate(input.client_error&.details), version: input.version, sent_at: input.sent_at } end 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
Version data entries
5 entries across 5 versions & 1 rubygems