Sha256: db171c750baad057bae6fd4f04255931cce82969a43f9d327ec4c20b1c4848a0

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

require "global_id"

module Plumbing
  module Actor
    class Transporter
      def marshal *arguments
        pack_array arguments
      end

      def unmarshal *arguments
        unpack_array arguments
      end

      private

      def pack argument
        case argument
        when GlobalID::Identification then pack_global_id argument
        when Array then pack_array argument
        when Hash then pack_hash argument
        else argument.clone
        end
      end

      def pack_array arguments
        arguments.map { |a| pack a }
      end

      def pack_hash arguments
        arguments.transform_values { |v| pack v }
      end

      def pack_global_id argument
        argument.to_global_id.to_s
      end

      def unpack argument
        case argument
        when String then unpack_string argument
        when Array then unpack_array argument
        when Hash then unpack_hash argument
        else argument
        end
      end

      def unpack_array arguments
        arguments.map { |a| unpack a }
      end

      def unpack_hash arguments
        arguments.to_h do |key, value|
          [key, unpack(value)]
        end
      end

      def unpack_string argument
        argument.start_with?("gid://") ? GlobalID::Locator.locate(argument) : argument
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
standard-procedure-plumbing-0.5.0 lib/plumbing/actor/transporter.rb
standard-procedure-plumbing-0.4.6 lib/plumbing/actor/transporter.rb
standard-procedure-plumbing-0.4.5 lib/plumbing/actor/transporter.rb
standard-procedure-plumbing-0.4.4 lib/plumbing/actor/transporter.rb
standard-procedure-plumbing-0.4.3 lib/plumbing/actor/transporter.rb
standard-procedure-plumbing-0.4.2 lib/plumbing/actor/transporter.rb
standard-procedure-plumbing-0.4.1 lib/plumbing/actor/transporter.rb
standard-procedure-plumbing-0.4.0 lib/plumbing/actor/transporter.rb