Sha256: 10110603339fd459bc4c9cbfbdd86a4aeb8c5400e3ae54a7ee3acccd69fe177d

Contents?: true

Size: 950 Bytes

Versions: 8

Compression:

Stored size: 950 Bytes

Contents

require "rack/builder"
class Rack::App::Endpoint::Builder

  def initialize(config)
    @config = config
  end

  def build
    builder = Rack::Builder.new
    apply_middleware_build_blocks(builder)
    builder.run(Rack::App::Endpoint::Executor.new(@config))
    builder.to_app
  end

  protected

  def apply_middleware_build_blocks(builder)
    builder_blocks.each do |builder_block|
      builder_block.call(builder)
    end
    builder.use(Rack::App::Middlewares::Configuration, @config)
    apply_hook_middlewares(builder)
  end

  def apply_hook_middlewares(builder)
    @config.app_class.before.each do |before_block|
      builder.use(Rack::App::Middlewares::Hooks::Before, before_block)
    end
    @config.app_class.after.each do |after_block|
      builder.use(Rack::App::Middlewares::Hooks::After, after_block)
    end
  end

  def builder_blocks
    [@config.app_class.middlewares, @config.middleware_builders_blocks].flatten
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rack-app-5.12.0 lib/rack/app/endpoint/builder.rb
rack-app-5.11.1 lib/rack/app/endpoint/builder.rb
rack-app-5.11.0 lib/rack/app/endpoint/builder.rb
rack-app-5.10.2 lib/rack/app/endpoint/builder.rb
rack-app-5.10.1 lib/rack/app/endpoint/builder.rb
rack-app-5.10.0 lib/rack/app/endpoint/builder.rb
rack-app-5.9.0 lib/rack/app/endpoint/builder.rb
rack-app-5.8.0 lib/rack/app/endpoint/builder.rb