Sha256: ccf667d1ec7a861cce25e39266eebf45d3469735e9fc885ba5e141f374bbc949

Contents?: true

Size: 1.15 KB

Versions: 5

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require 'ffi'
require 'pathname'
require_relative 'platform'

module SleepingKangaroo12
  module Build
    # taken from:
    # https://github.com/ffi/ffi-compiler/blob/master/lib/ffi-compiler/loader.rb
    module Loader
      def self.find(name, start_path = nil)
        library = Platform.instance.map_library_name(name)
        root = false
        ::Pathname.new(start_path || caller_path(caller[0])).ascend do |path|
          Dir.glob("#{path}/**/{#{::FFI::Platform::ARCH}-#{::FFI::Platform::OS}/#{library},#{library}}") do |f|
            return f
          end

          break if root

          # Next iteration will be the root of the gem if this is the lib/ dir - stop after that
          root = ::File.basename(path) == 'lib'
        end
        raise ::LoadError, "cannot find '#{name}' library"
      end

      def self.caller_path(line = caller[0])
        if ::FFI::Platform::OS == 'windows'
          drive = line[0..1]
          path =  line[2..].split(/:/)[0]
          full_path = drive + path
        else
          full_path = line.split(/:/)[0]
        end
        ::File.dirname full_path
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sleeping_kangaroo12-0.0.6 lib/sleeping_kangaroo12/build/loader.rb
sleeping_kangaroo12-0.0.4 lib/sleeping_kangaroo12/build/loader.rb
sleeping_kangaroo12-0.0.3 lib/sleeping_kangaroo12/build/loader.rb
sleeping_kangaroo12-0.0.2 lib/sleeping_kangaroo12/build/loader.rb
sleeping_kangaroo12-0.0.1 lib/sleeping_kangaroo12/build/loader.rb