Module: YAMLStar::LibYAMLStar

Extended by:
Fiddle::Importer
Defined in:
lib/yamlstar.rb

Class Method Summary collapse

Class Method Details

.extensionObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/yamlstar.rb', line 17

def self.extension
  case RUBY_PLATFORM
  when /darwin/
    "dylib"
  when /linux/
    "so"
  when /mswin|mingw|cygwin/
    "dll"
  else
    raise Error, "Unsupported platform #{RUBY_PLATFORM} for yamlstar."
  end
end

.find_libraryObject

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/yamlstar.rb', line 46

def self.find_library
  library_paths.each do |dir|
    library_names.each do |name|
      path = File.join(dir, name)
      return path if File.exist?(path)
    end
  end

  raise Error, <<~ERROR
    Shared library file `libyamlstar.#{extension}` not found
    Search paths: #{library_paths.join(File::PATH_SEPARATOR)}
    Try: curl -sSL https://yamlstar.org/install | LIB=1 bash
  ERROR
end

.library_namesObject



30
31
32
33
# File 'lib/yamlstar.rb', line 30

def self.library_names
  base = "libyamlstar.#{extension}"
  [base, "#{base}.#{LIBYAMLSTAR_VERSION}"]
end

.library_pathsObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/yamlstar.rb', line 35

def self.library_paths
  paths = []
  dev_path = File.expand_path("../../libyamlstar/lib", __dir__)
  paths << dev_path
  env_var = extension == "dll" ? "PATH" : "LD_LIBRARY_PATH"
  paths.concat(ENV.fetch(env_var, "").split(File::PATH_SEPARATOR))
  paths << "/usr/local/lib" unless extension == "dll"
  paths << File.join(ENV.fetch("HOME", ""), ".local", "lib")
  paths.reject(&:empty?)
end