Module: Kreuzberg::APIProxy

Defined in:
lib/kreuzberg/api_proxy.rb

Overview

Examples:

Start the server

With block

Defined Under Namespace

Classes: Error, MissingBinaryError, Server, ServerError

Class Method Summary collapse

Class Method Details

.find_api_binaryPathname

Find the API binary

Returns:

  • (Pathname)

    Path to binary

Raises:



104
105
106
107
108
109
110
# File 'lib/kreuzberg/api_proxy.rb', line 104

def find_api_binary
  binary_name = Gem.win_platform? ? 'kreuzberg.exe' : 'kreuzberg'
  found = CLIProxy.search_paths(binary_name).find(&:file?)
  return found if found

  raise MissingBinaryError, missing_binary_message
end

.missing_binary_messageString

Error message for missing binary

Returns:

  • (String)


116
117
118
119
120
121
122
123
# File 'lib/kreuzberg/api_proxy.rb', line 116

def missing_binary_message
  <<~MSG.strip
    kreuzberg binary not found for API server. Build it with:
    `cargo build --release --package kreuzberg-cli`

    Or ensure kreuzberg is installed with API support.
  MSG
end

.run(port: 8000, host: '0.0.0.0') {|Server| ... } ⇒ Object

Run server with a block

Examples:

Kreuzberg::APIProxy.run(port: 8000) do |server|
  # Make API requests
end

Parameters:

  • port (Integer) (defaults to: 8000)

    Port to run on

  • host (String) (defaults to: '0.0.0.0')

    Host to bind to

Yields:

  • (Server)

    Yields server instance

Returns:

  • (Object)

    Block result



91
92
93
94
95
96
97
# File 'lib/kreuzberg/api_proxy.rb', line 91

def run(port: 8000, host: '0.0.0.0')
  server = Server.new(port: port, host: host)
  server.start
  yield server
ensure
  server&.stop
end