Sha256: a159853986ad067cb444830807c0369782ec19179bb115f10547acdcb114c89d

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
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(app)
    builder.to_app
  end

  protected

  def app
    case @config.type
    when :endpoint
      Rack::App::Endpoint::Executor.new(@config)
    else
      @config.callable
    end
  end

  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.endpoint_specific_middlewares].flatten
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-app-6.4.1 lib/rack/app/endpoint/builder.rb
rack-app-6.4.0 lib/rack/app/endpoint/builder.rb
rack-app-6.3.3 lib/rack/app/endpoint/builder.rb
rack-app-6.3.2 lib/rack/app/endpoint/builder.rb
rack-app-6.3.1 lib/rack/app/endpoint/builder.rb
rack-app-6.3.0 lib/rack/app/endpoint/builder.rb
rack-app-6.2.0 lib/rack/app/endpoint/builder.rb
rack-app-6.1.0 lib/rack/app/endpoint/builder.rb
rack-app-6.0.0 lib/rack/app/endpoint/builder.rb