Class: Hooks::Core::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/hooks/core/builder.rb

Overview

Main builder that orchestrates the webhook server setup

Instance Method Summary collapse

Constructor Details

#initialize(config: nil, log: nil, **extra_components) ⇒ Builder

Initialize builder with configuration options

Parameters:

  • config (String, Hash) (defaults to: nil)

    Path to config file or config hash

  • log (Logger) (defaults to: nil)

    Custom logger instance

  • **extra_components (Hash)

    Arbitrary user-defined components to make available to handlers



19
20
21
22
23
# File 'lib/hooks/core/builder.rb', line 19

def initialize(config: nil, log: nil, **extra_components)
  @log = log
  @config_input = config
  @extra_components = extra_components
end

Instance Method Details

#buildObject

Build and return Rack-compatible application

Returns:

  • (Object)

    Rack-compatible application



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/hooks/core/builder.rb', line 28

def build
  # Load and validate configuration
  config = load_and_validate_config

  # Create logger unless a custom logger is provided
  if @log.nil?
    @log = LoggerFactory.create(
      log_level: config[:log_level],
      custom_logger: @custom_logger
    )
  end

  @log.debug("global config loaded: #{config.inspect}")

  Hooks::Log.instance = @log

  # Register user-defined components globally
  Hooks::Core::GlobalComponents.register_extra_components(@extra_components)

  # Hydrate our Retryable instance
  Retry.setup!(log: @log)

  # Load all plugins at boot time
  load_plugins(config)

  # Load endpoints
  endpoints = load_endpoints(config)

  # Log startup
  @log.info "starting hooks server v#{Hooks::VERSION}"
  @log.info "config: #{endpoints.size} endpoints loaded"
  @log.info "environment: #{config[:environment]}"
  @log.info "available endpoints: #{endpoints.map { |e| e[:path] }.join(', ')}"

  # Build and return Grape API class
  Hooks::App::API.create(
    config:,
    endpoints:,
    log: @log
  )
end