Sha256: eaebc6afb258b75b8667126d7beade3455bf84658266fc7d220ed7d95bbc3a57

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Common
    module Plugins
      module HasCallbacks
        module Concern
          include Support::Concern

          class_methods do
            ##
            # @api private
            #
            # @return [ConvenientService::Common::Plugins::HasCallbacks::Entities::CallbackCollection]
            #
            def callbacks
              internals_class.cache.fetch(:callbacks) { Entities::CallbackCollection.new }
            end

            ##
            # @api public
            #
            # @param type [Symbol]
            # @param block [Proc]
            # @return [ConvenientService::Common::Plugins::HasCallbacks::Entities::Callback]
            #
            def before(type, &block)
              callbacks.create(types: [:before, type], block: block)
            end

            ##
            # @api public
            #
            # @param type [Symbol]
            # @param block [Proc]
            # @return [ConvenientService::Common::Plugins::HasCallbacks::Entities::Callback]
            #
            def after(type, &block)
              callbacks.create(types: [:after, type], block: block)
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/common/plugins/has_callbacks/concern.rb
convenient_service-0.19.0 lib/convenient_service/common/plugins/has_callbacks/concern.rb
convenient_service-0.18.0 lib/convenient_service/common/plugins/has_callbacks/concern.rb