Sha256: 602bcde4d5ee6fb93ce2d89a4050b5ef24bdc2acfdc9bd9287e37cb6d5d9df19

Contents?: true

Size: 1.41 KB

Versions: 18

Compression:

Stored size: 1.41 KB

Contents

require 'acfs/service/middleware/stack'

module Acfs
  class Service
    # Module providing all function to register middlewares
    # on services and process queued request through the
    # middleware stack.
    #
    module Middleware
      extend ActiveSupport::Concern

      # @api private
      # @return [Request]
      #
      def prepare(request)
        self.class.middleware.call request
      end

      module ClassMethods
        # @!method use(klass, *args, &block)
        #   @api public
        #
        #   Register a new middleware to be used for this service.
        #
        #   @example
        #     class MyService < Acfs::Service
        #       self.base_url = 'http://my.srv'
        #       use Acfs::Middleware::JSON
        #     end
        #
        #   @param [Class] klass Middleware class to append
        #   @param [Array<Object>] args Arguments passed to klass initialize
        #   @param [Proc] block Block passed to klass initialize
        #   @return [undefined]
        #
        def use(klass, *args, &block)
          # Backward compatible behavior
          middleware.insert(0, klass, *args, &block)
        end

        # @api private
        #
        # Return top most middleware.
        #
        # @return [#call]
        #
        def middleware
          @middleware ||= Stack.new
        end

        # @deprecated
        delegate :clear, to: :middleware
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
acfs-1.3.2 lib/acfs/service/middleware.rb
acfs-1.3.1 lib/acfs/service/middleware.rb
acfs-1.3.0 lib/acfs/service/middleware.rb
acfs-1.2.1 lib/acfs/service/middleware.rb
acfs-0.50.0 lib/acfs/service/middleware.rb
acfs-1.2.0 lib/acfs/service/middleware.rb
acfs-0.49.1 lib/acfs/service/middleware.rb
acfs-1.1.1 lib/acfs/service/middleware.rb
acfs-0.49.0 lib/acfs/service/middleware.rb
acfs-1.1.0 lib/acfs/service/middleware.rb
acfs-0.48.2 lib/acfs/service/middleware.rb
acfs-1.0.1 lib/acfs/service/middleware.rb
acfs-0.48.1 lib/acfs/service/middleware.rb
acfs-1.0.0 lib/acfs/service/middleware.rb
acfs-0.48.0 lib/acfs/service/middleware.rb
acfs-0.47.0 lib/acfs/service/middleware.rb
acfs-0.46.0 lib/acfs/service/middleware.rb
acfs-0.45.0 lib/acfs/service/middleware.rb