Sha256: 20f450ab26a27daea65d1cc5ce6ede0cb770bcc631840a55041175c57ca99f85

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Support
    module DependencyContainer
      module Import
        include Support::Concern

        class_methods do
          ##
          # @param full_name [String, Symbol]
          # @param from [Module]
          # @param scope [:instance, :class]
          # @param prepend [Boolean]
          # @return [ConvenientService::Support::DependencyContainer::Entities::Method]
          #
          def import(full_name, from:, scope: Constants::DEFAULT_SCOPE, prepend: Constants::DEFAULT_PREPEND)
            Commands::AssertValidScope.call(scope: scope)

            raise Errors::NotExportableModule.new(mod: from) unless Utils::Module.include_module?(from, DependencyContainer::Export)

            method = from.exported_methods.find_by(full_name: full_name, scope: scope)

            raise Errors::NotExportedMethod.new(method_name: full_name, method_scope: scope, mod: from) unless method

            Commands::ImportMethod.call(importing_module: self, exported_method: method, prepend: prepend)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
convenient_service-0.11.0 lib/convenient_service/support/dependency_container/import.rb
convenient_service-0.10.1 lib/convenient_service/support/dependency_container/import.rb
convenient_service-0.10.0 lib/convenient_service/support/dependency_container/import.rb
convenient_service-0.9.0 lib/convenient_service/support/dependency_container/import.rb
convenient_service-0.8.0 lib/convenient_service/support/dependency_container/import.rb
convenient_service-0.7.0 lib/convenient_service/support/dependency_container/import.rb
convenient_service-0.6.0 lib/convenient_service/support/dependency_container/import.rb