class Rack::App::Endpoint::Builder

Public Class Methods

new(config) click to toggle source
# File lib/rack/app/endpoint/builder.rb, line 5
def initialize(config)
  @config = config
end

Public Instance Methods

to_app() click to toggle source
# File lib/rack/app/endpoint/builder.rb, line 9
def to_app
  build.to_app
end

Protected Instance Methods

app() click to toggle source
# File lib/rack/app/endpoint/builder.rb, line 22
def app
  case @config.type
  when :endpoint
    Rack::App::Endpoint::Executor.new(@config)
  else
    @config.callable
  end
end
apply_catcher_on_need(builder) click to toggle source
# File lib/rack/app/endpoint/builder.rb, line 43
def apply_catcher_on_need(builder)
  at_least_one_hook_requested = @config.ancestor_apps.any? do |app_class|
    app_class.before.length + app_class.after.length > 0
  end

  if at_least_one_hook_requested
    builder.use(Rack::App::Endpoint::Catcher, @config)
  end
end
apply_hook_middlewares(app_class, builder) click to toggle source
# File lib/rack/app/endpoint/builder.rb, line 53
def apply_hook_middlewares(app_class, builder)
  app_class.before.each do |before_block|
    builder.use(Rack::App::Middlewares::Hooks::Before, before_block)
  end

  app_class.after.each do |after_block|
    builder.use(Rack::App::Middlewares::Hooks::After, after_block)
  end
end
apply_middleware_build_blocks(builder) click to toggle source
# File lib/rack/app/endpoint/builder.rb, line 31
def apply_middleware_build_blocks(builder)
  @config.middlewares.each do |builder_block|
    builder.instance_exec(builder, &builder_block)
  end
  builder.use(Rack::App::Middlewares::Configuration, @config)

  apply_catcher_on_need(builder)
  @config.ancestor_apps.reverse_each do |app_class|
    apply_hook_middlewares(app_class, builder)
  end
end
build() click to toggle source
# File lib/rack/app/endpoint/builder.rb, line 15
def build
  builder = Rack::Builder.new
  apply_middleware_build_blocks(builder)
  builder.run(app)
  builder
end