Sha256: 2c50a8e7c29b8b05e4a645eba111c85f32d175fbff32d62c24bc3c6e908babe1

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Support
    module DependencyContainer
      module Export
        include Support::Concern

        ##
        # @param klass [Class, Module]
        # @return [Module]
        #
        included do |klass|
          ::ConvenientService.raise Exceptions::NotModule.new(klass: klass) unless klass.instance_of?(::Module)
        end

        class_methods do
          ##
          # @param slug [String, Symbol]
          # @param scope [:instance, :class]
          # @param body [Proc]
          # @return [ConvenientService::Support::DependencyContainer::Entities::Method]
          #
          # @internal
          #   NOTE: `export` does NOT accept `prepend` kwarg intentionally.
          #   It is done to follow "the Ruby way".
          #   You won't ever see a module in Ruby that contains methods for `include` and `prepend` at the same time.
          #   So why `export` should allow to do it?
          #
          def export(slug, scope: Constants::DEFAULT_SCOPE, &body)
            Commands::AssertValidScope.call(scope: scope)

            Entities::Method.new(slug: slug, scope: scope, body: body).tap { |method| exported_methods << method }
          end

          ##
          # @return [ConvenientService::Support::DependencyContainer::Entities::MethodCollection]
          #
          def exported_methods
            @exported_methods ||= Entities::MethodCollection.new
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/support/dependency_container/export.rb
convenient_service-0.19.0 lib/convenient_service/support/dependency_container/export.rb
convenient_service-0.18.0 lib/convenient_service/support/dependency_container/export.rb
convenient_service-0.17.0 lib/convenient_service/support/dependency_container/export.rb