Class: Hooks::App::RackEnvBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/hooks/app/rack_env_builder.rb

Overview

Builds Rack environment hash for lifecycle hooks and handler processing

This class centralizes the construction of the Rack environment that gets passed to lifecycle hooks and handlers, ensuring consistency and making it easy to reference the environment structure.

Examples:

Building a Rack environment

builder = RackEnvBuilder.new(request, headers, request_context)
rack_env = builder.build

Instance Method Summary collapse

Constructor Details

#initialize(request, headers, request_context, endpoint_config, start_time, full_path) ⇒ RackEnvBuilder

Initialize the builder with required components

Parameters:

  • request (Grape::Request)

    The Grape request object

  • headers (Hash)

    Request headers hash

  • request_context (Hash)

    Request context containing metadata

  • endpoint_config (Hash)

    Endpoint configuration

  • start_time (Time)

    Request start time

  • full_path (String)

    Full request path including root path

Options Hash (request_context):

  • :request_id (String)

    Unique request identifier

  • :handler (String)

    Handler class name



26
27
28
29
30
31
32
33
# File 'lib/hooks/app/rack_env_builder.rb', line 26

def initialize(request, headers, request_context, endpoint_config, start_time, full_path)
  @request = request
  @headers = headers
  @request_context = request_context
  @endpoint_config = endpoint_config
  @start_time = start_time
  @full_path = full_path
end

Instance Method Details

#buildHash

Build the Rack environment hash

Constructs a hash containing standard Rack environment variables plus Hooks-specific extensions for lifecycle hooks and handlers.

Returns:

  • (Hash)

    Complete Rack environment hash



41
42
43
44
45
# File 'lib/hooks/app/rack_env_builder.rb', line 41

def build
  rack_env = build_base_environment
  add_http_headers(rack_env)
  rack_env
end