Sha256: 81ec03b26116686e3251aa1a5d0a8cefc0d7c24f23b449fb626b7cfc925b3028
Contents?: true
Size: 825 Bytes
Versions: 16
Compression:
Stored size: 825 Bytes
Contents
# frozen_string_literal: true # Released under the MIT License. # Copyright, 2019-2024, by Samuel Williams. require_relative '../middleware' module Protocol module HTTP class Middleware class Builder def initialize(default_app = NotFound) @use = [] @app = default_app end def use(middleware, *arguments, **options, &block) @use << proc {|app| middleware.new(app, *arguments, **options, &block)} end def run(app) @app = app end def to_app @use.reverse.inject(@app) {|app, use| use.call(app)} end end def self.build(&block) builder = Builder.new if block_given? if block.arity == 0 builder.instance_exec(&block) else yield builder end end return builder.to_app end end end end
Version data entries
16 entries across 16 versions & 1 rubygems