Module: Box2D::NativeLoader
- Defined in:
- lib/box2d/native_loader.rb
Constant Summary collapse
- ENVIRONMENT_KEY =
"BOX2D_LIBRARY_PATH"- EXTENSION_NAME =
"native.#{RbConfig::CONFIG.fetch("DLEXT")}"
Class Method Summary collapse
- .candidates ⇒ Object
- .library_path ⇒ Object
- .missing_library_message ⇒ Object
- .validate_explicit_path(path) ⇒ Object
Class Method Details
.candidates ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/box2d/native_loader.rb', line 22 def candidates relative_path = File.join("box2d", EXTENSION_NAME) load_path_candidates = $LOAD_PATH.map { |path| File.(relative_path, path) } source_candidate = File.("../../ext/box2d/#{EXTENSION_NAME}", __dir__) (load_path_candidates << source_candidate).uniq end |
.library_path ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/box2d/native_loader.rb', line 12 def library_path explicit_path = ENV[ENVIRONMENT_KEY] return validate_explicit_path(explicit_path) if explicit_path path = candidates.find { |candidate| File.file?(candidate) } return path if path raise LoadError, end |
.missing_library_message ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/box2d/native_loader.rb', line 37 def <<~MESSAGE.chomp Box2D native library was not found. Reinstall the gem to build it, run `bundle exec rake native:compile` from a source checkout, or set #{ENVIRONMENT_KEY} to a compatible Box2D 3.1 shared library. MESSAGE end |
.validate_explicit_path(path) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/box2d/native_loader.rb', line 30 def validate_explicit_path(path) = File.(path) return if File.file?() raise LoadError, "#{ENVIRONMENT_KEY} does not point to a file: #{}" end |