Sha256: ab84528b30fd24677a7a0d1a6a6fc6ac019eb46c3cf1c999aaf4b6549ab5ba4c

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Support
    module DependencyContainer
      module Errors
        class InvalidScope < ConvenientService::Error
          ##
          # @param scope [Object]
          # @return [void]
          #
          def initialize(scope:)
            message = <<~TEXT
              Scope `#{scope.inspect}` is NOT valid.

              Valid options are #{printable_valid_scopes}.
            TEXT

            super(message)
          end

          private

          ##
          # @return [String]
          #
          def printable_valid_scopes
            Constants::SCOPES.map { |scope| "`:#{scope}`" }.join(", ")
          end
        end

        class NotExportableModule < ConvenientService::Error
          ##
          # @param mod [Module]
          # @return [void]
          #
          def initialize(mod:)
            message = <<~TEXT
              Module `#{mod}` can NOT export methods.

              Did you forget to include `ConvenientService::Container.export` into it?
            TEXT

            super(message)
          end
        end

        class NotExportedMethod < ConvenientService::Error
          ##
          # @param method_name [String]
          # @param method_scope [Symbol]
          # @param mod [Module]
          # @return [void]
          #
          def initialize(method_name:, method_scope:, mod:)
            message = <<~TEXT
              Module `#{mod}` does NOT export method `#{method_name}` with `#{method_scope}` scope.

              Did you forget to export if from `#{mod}`? For example:

              module #{mod}
                export #{method_name}, scope: :#{method_scope} do |*args, **kwargs, &block|
                  # ...
                end
              end
            TEXT

            super(message)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
convenient_service-0.6.0 lib/convenient_service/support/dependency_container/errors.rb