Sha256: 18dda2bd1bd9d5c45f8cf473abbe5f939e1b3982beb3a4621cd1e8f678da0e0e
Contents?: true
Size: 1.42 KB
Versions: 3
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true module Hanami class API # Hanami::API middleware stack # # @since 0.1.0 # @api private module Middleware require "hanami/api/middleware/app" require "hanami/api/middleware/trie" # Middleware stack # # @since 0.1.0 # @api private class Stack # @since 0.1.0 # @api private def initialize(prefix) @prefix = prefix @stack = {} end # @since 0.1.0 # @api private def use(path, middleware, *args, &blk) # FIXME: test with prefix when Hanami::API.settings and prefix will be supported @stack[path] ||= [] @stack[path].push([middleware, args, blk]) end # @since 0.1.1 # @api private def to_hash @stack.each_with_object({}) do |(path, _), result| result[path] = stack_for(path) end end # @since 0.1.1 # @api private def finalize(app) mapping = to_hash return app if mapping.empty? App.new(app, mapping) end private # @since 0.1.1 # @api private def stack_for(current_path) @stack.each_with_object([]) do |(path, stack), result| next unless current_path.start_with?(path) result.push(stack) end.flatten(1) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hanami-api-0.2.0 | lib/hanami/api/middleware.rb |
hanami-api-0.1.2 | lib/hanami/api/middleware.rb |
hanami-api-0.1.1 | lib/hanami/api/middleware.rb |