Sha256: 86ff0a92ecaecec512cf124d13d076e05d6996428a314d68be25c5c1d5e2a7df

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

require "faster_path/version"
require 'pathname'
require "ffi"
require 'faster_path/asset_resolution'

module FasterPath
  FFI_LIBRARY = begin
    prefix = Gem.win_platform? ? "" : "lib"
    "#{File.expand_path("../target/release/", __dir__)}/#{prefix}faster_path.#{FFI::Platform::LIBSUFFIX}"
  end
  require 'fiddle'
  library = Fiddle.dlopen(FFI_LIBRARY)
  Fiddle::Function.
    new(library['Init_faster_pathname'], [], Fiddle::TYPE_VOIDP).
    call

  FasterPathname.class_eval do
    private :add_trailing_separator
    private :basename
    private :chop_basename
    private :dirname
    private :entries
    private :extname
    private :plus
  end

  def self.rust_arch_bits
    Rust.rust_arch_bits
  end

  def self.ruby_arch_bits
    1.size * 8
  end

  def self.absolute?(pth)
    FasterPathname.allocate.send(:absolute?, pth)
  end

  def self.add_trailing_separator(pth)
    FasterPathname.allocate.send(:add_trailing_separator, pth)
  end

  def self.blank?(str)
    "#{str}".strip.empty?
  end

  def self.basename(pth, ext="")
    FasterPathname.allocate.send(:basename, pth, ext)
  end

  def self.chop_basename(pth)
    result = FasterPathname.allocate.send(:chop_basename, pth)
    result unless result.empty?
  end

  def self.directory?(pth)
    FasterPathname.allocate.send(:directory?, pth)
  end

  def self.dirname(pth)
    FasterPathname.allocate.send(:dirname, pth)
  end

  def self.entries(pth)
    FasterPathname.allocate.send(:entries, pth)
  end

  def self.extname(pth)
    FasterPathname.allocate.send(:extname, pth)
  end

  def self.has_trailing_separator?(pth)
    FasterPathname.allocate.send(:has_trailing_separator?, pth)
  end

  def self.plus(pth, pth2)
    FasterPathname.allocate.send(:plus, pth, pth2)
  end

  def self.relative?(pth)
    FasterPathname.allocate.send(:relative?, pth)
  end

  module Rust
    extend FFI::Library
    ffi_lib ::FasterPath::FFI_LIBRARY

    attach_function :rust_arch_bits, [], :int32
  end
  private_constant :Rust
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
faster_path-0.2.0 lib/faster_path.rb