Sha256: c555de1e444e9c75aa5ca17cc90e531a1fc5327e29420d0fa11f8f8c9d15825e

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Transmutation
  module Serialization
    class Lookup
      # @api public
      class SerializerNotFound < Transmutation::Error
        attr_reader :object, :namespace, :name

        def initialize(object, namespace: nil, name: nil)
          @object = object
          @namespace = namespace
          @name = name

          super [
            "Couldn't find serializer for #{object.class.name}#{namespace.empty? ? "" : " in #{namespace}"}.",
            "Tried looking for the following classes: #{attempted_lookups}."
          ].join(" ")
        end

        private

        def attempted_lookups
          namespaces_chain.map { |namespace| [namespace, name].join("::") }.join(", ")
        end

        def namespaces_chain
          @namespaces_chain ||= begin
            namespace_parts = namespace.split("::")

            namespace_parts.filter_map.with_index do |part, index|
              [*namespace_parts[...index], part].join("::")
            end.reverse
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
transmutation-0.4.5 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.4.4 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.4.1 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.3.6 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.3.5 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.3.4 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.3.3 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.3.1 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.3.0 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.2.3 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.2.2 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.2.1 lib/transmutation/serialization/lookup/serializer_not_found.rb
transmutation-0.2.0 lib/transmutation/serialization/lookup/serializer_not_found.rb