class FFIDB::Registry

Constants

GIT_HTTPS_URL

Attributes

path[R]

Public Class Methods

default_path() click to toggle source

@return [Pathname]

# File lib/ffidb/registry.rb, line 15
def self.default_path
  Pathname(ENV['HOME']).join('.ffidb')
end
new(path = nil) click to toggle source

@param [Pathname, to_s] path @raise [RegistryVersionMismatch] if this version of FFIDB.rb is unable to open the registry

# File lib/ffidb/registry.rb, line 29
def initialize(path = nil)
  @path = Pathname(path || self.class.default_path)

  if (version_file = @path.join('.cli-version')).exist?
    min_version = version_file.read.chomp.split('.').map(&:to_i)
    if (FFIDB::VERSION.to_a <=> min_version).negative?
      raise RegistryVersionMismatch, "FFIDB.rb #{min_version.join('.')}+ is required for the registry directory #{@path}"
    end
  end
end
open(path = nil, &block) click to toggle source

@param [Pathname, to_s] path

# File lib/ffidb/registry.rb, line 21
def self.open(path = nil, &block)
  registry = self.new(path)
  block_given? ? block.call(registry) : registry
end

Public Instance Methods

each_library() { |open_library| ... } click to toggle source

@yield [library] @return [Enumerator]

# File lib/ffidb/registry.rb, line 43
def each_library(&block)
  return self.to_enum(:each_library) unless block_given?
  library_names = self.path.glob('*')
    .select { |path| path.directory? && !(path.symlink?) }
    .map { |path| path.basename.to_s }
    .sort
  library_names.each do |library_name|
    yield self.open_library(library_name)
  end
end
find_symbols(matcher, kind: nil) { |symbol, library| ... } click to toggle source

@param [Glob, ===] matcher @param [Symbol] kind @yield [function] @yield [library] @return [Enumerator]

# File lib/ffidb/registry.rb, line 72
def find_symbols(matcher, kind: nil, &block)
  return self.to_enum(:find_symbols) unless block_given?
  count = 0
  self.each_library do |library|
    library.each_symbol do |symbol|
      next if kind && kind != symbol.kind
      if matcher === symbol.name.to_s
        count += 1
        yield symbol, library
      end
    end
  end
  count > 0 ? count : nil
end
open_library(library_name, library_version = nil, &block) click to toggle source

@param [String, to_s] library_name @param [String, to_s] library_version @yield [library] @return [Library]

# File lib/ffidb/registry.rb, line 59
def open_library(library_name, library_version = nil, &block)
  library_path = self.path.join(library_name.to_s)
  return nil unless library_path.directory?
  library = Library.new(library_name, library_version, library_path)
  block_given? ? block.call(library) : library
end