Class: Honker::ExtensionResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/honker.rb

Overview

Resolves the path to the Honker SQLite loadable extension. Platform gems ship it bundled in lib/honker/; an explicit path and the HONKER_EXTENSION_PATH override take precedence.

Instance Method Summary collapse

Constructor Details

#initialize(env: ENV.fetch("HONKER_EXTENSION_PATH", nil), bundled: nil) ⇒ ExtensionResolver

Returns a new instance of ExtensionResolver.



40
41
42
43
# File 'lib/honker.rb', line 40

def initialize(env: ENV.fetch("HONKER_EXTENSION_PATH", nil), bundled: nil)
  @env = env
  @bundled = bundled || File.expand_path("honker/#{extension_filename}", __dir__)
end

Instance Method Details

#resolve(extension_path = nil) ⇒ Object

Returns the extension path: an explicit extension_path, else HONKER_EXTENSION_PATH, else the bundled extension. Raises Honker::Error when HONKER_EXTENSION_PATH or the bundled extension is missing.

Raises:



49
50
51
52
53
54
55
56
57
58
# File 'lib/honker.rb', line 49

def resolve(extension_path = nil)
  return extension_path unless extension_path.nil?
  return env_extension unless env.nil? || env.empty?

  path = bundled
  return path if File.file?(path)

  raise Error, "Honker SQLite extension not found at #{path}; " \
               "set HONKER_EXTENSION_PATH or pass extension_path:"
end