Module: YAMLScript::LibYAMLScript

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

Overview

A low-level interface to the native library

Class Method Summary collapse

Class Method Details

.extensionObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/yamlscript.rb', line 25

def self.extension
  case RUBY_PLATFORM
  when /darwin/
    'dylib'
  when /linux/
    'so'
  else
    raise Error, "Unsupported platform #{RUBY_PLATFORM} for yamlscript."
  end
end

.find_libyamlscript_pathObject

Find the libyamlscript shared library file path

Raises:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/yamlscript.rb', line 52

def self.find_libyamlscript_path
  name = libyamlscript_name
  path = ld_library_paths.map {
    |dir| File.join(dir, name) }.detect { |file| File.exist?(file)
  }

  vers = YAMLSCRIPT_VERSION
  raise Error, <<-ERROR unless path

Shared library file `#{name}` not found
Try: curl https://yamlscript.org/install | VERSION=#{vers} LIB=1 bash
See: https://github.com/yaml/yamlscript/wiki/Installing-YAMLScript
ERROR

  path
end

.ld_library_pathsObject

Returns an array of library paths extracted from the LD_LIBRARY_PATH environment variable. If the environment variable is not set will return an array with ‘/usr/local/lib` only.



44
45
46
47
48
49
# File 'lib/yamlscript.rb', line 44

def self.ld_library_paths
  env_value = ENV.fetch('LD_LIBRARY_PATH', '')
  paths = env_value.split(':')
  paths << '/usr/local/lib'
  paths << ENV.fetch('HOME', '') + '/.local/lib'
end

.libyamlscript_nameObject



36
37
38
# File 'lib/yamlscript.rb', line 36

def self.libyamlscript_name
  "libyamlscript.#{extension}.#{YAMLSCRIPT_VERSION}"
end