Sha256: b859c2a0b41cc2c09bf72b50d5a683a460f37e35c4c78c6e6744a14efa29f5c4

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 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|
          raise Errors::NotModule.new(klass: klass) unless klass.instance_of?(::Module)
        end

        class_methods do
          ##
          # @param full_name [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(full_name, scope: Constants::DEFAULT_SCOPE, &body)
            Commands::AssertValidScope.call(scope: scope)

            Entities::Method.new(full_name: full_name, 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

5 entries across 5 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/support/dependency_container/export.rb
convenient_service-0.11.0 lib/convenient_service/support/dependency_container/export.rb
convenient_service-0.10.1 lib/convenient_service/support/dependency_container/export.rb
convenient_service-0.10.0 lib/convenient_service/support/dependency_container/export.rb
convenient_service-0.9.0 lib/convenient_service/support/dependency_container/export.rb