Top Level Namespace

Defined Under Namespace

Modules: RDKitChem

Instance Method Summary collapse

Instance Method Details

#find_rdkit_native_extensionObject

Try to load the native extension from multiple possible locations:

  1. Pre-compiled gem: lib/rdkit_chem/<ruby_version>/RDKitChem.so

  2. Source-compiled gem: rdkit_chem/lib/RDKitChem.so (legacy location)

Raises:

  • (LoadError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rdkit_chem.rb', line 9

def find_rdkit_native_extension
  ruby_version = "#{RUBY_VERSION.split('.')[0..1].join('.')}.0"

  # Location 1: Pre-compiled gem (platform-specific)
  precompiled_path = File.expand_path("rdkit_chem/#{ruby_version}", __dir__)
  if File.directory?(precompiled_path)
    return precompiled_path
  end

  # Location 2: Source-compiled gem (legacy rdkit_chem/lib/)
  source_compiled_path = File.expand_path('../rdkit_chem/lib', __dir__)
  if File.exist?(File.join(source_compiled_path, 'RDKitChem.so')) ||
     File.exist?(File.join(source_compiled_path, 'RDKitChem.bundle'))
    return source_compiled_path
  end

  raise LoadError, "Cannot find RDKitChem native extension. " \
                   "Searched in:\n  - #{precompiled_path}\n  - #{source_compiled_path}"
end