Class: FFIDB::Registry
- Inherits:
-
Object
- Object
- FFIDB::Registry
- Defined in:
- lib/ffidb/registry.rb
Constant Summary collapse
- GIT_HTTPS_URL =
'https://github.com/ffidb/ffidb.git'.freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #each_library {|library| ... } ⇒ Enumerator
- #find_symbols(matcher, kind: nil) {|function| ... } ⇒ Enumerator
-
#initialize(path = nil) ⇒ Registry
constructor
A new instance of Registry.
- #open_library(library_name, library_version = nil) {|library| ... } ⇒ Library
Constructor Details
#initialize(path = nil) ⇒ Registry
Returns a new instance of Registry.
29 30 31 32 33 34 35 36 37 38 |
# 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 |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/ffidb/registry.rb', line 11 def path @path end |
Class Method Details
.default_path ⇒ Pathname
15 16 17 |
# File 'lib/ffidb/registry.rb', line 15 def self.default_path Pathname(ENV['HOME']).join('.ffidb') end |
.open(path = nil, &block) ⇒ Object
21 22 23 24 |
# File 'lib/ffidb/registry.rb', line 21 def self.open(path = nil, &block) registry = self.new(path) block_given? ? block.call(registry) : registry end |
Instance Method Details
#each_library {|library| ... } ⇒ Enumerator
43 44 45 46 47 48 49 50 51 52 |
# 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) {|function| ... } ⇒ Enumerator
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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) {|library| ... } ⇒ Library
59 60 61 62 63 64 |
# 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 |