clowne-rb/clowne

View on GitHub
lib/clowne/utils/clone_mapper.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require "clowne/ext/record_key"

module Clowne
  module Utils
    class CloneMapper # :nodoc: all
      def initialize
        @store = {}
      end

      def add(origin, clone)
        @store[origin] ||= clone
      end

      def clone_of(origin)
        @store[origin]
      end

      def origin_of(clone)
        origin, _clone = @store.rassoc(clone)
        origin
      end
    end
  end
end