Module: YAMLScript::LibYS
- Extended by:
- Fiddle::Importer
- Defined in:
- lib/yamlscript.rb
Overview
A low-level interface to the native library
Class Method Summary collapse
- .extension ⇒ Object
-
.find_libys_path ⇒ Object
Find the libys shared library file path.
-
.ld_library_paths ⇒ Object
Returns an array of library paths extracted from the LD_LIBRARY_PATH environment variable (PATH on Windows).
- .libys_name ⇒ Object
- .windows? ⇒ Boolean
Class Method Details
.extension ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yamlscript.rb', line 29 def self.extension case RUBY_PLATFORM when /darwin/ 'dylib' when /linux/ 'so' when /mingw|mswin/ 'dll' else raise Error, "Unsupported platform #{RUBY_PLATFORM} for yamlscript." end end |
.find_libys_path ⇒ Object
Find the libys shared library file path
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/yamlscript.rb', line 65 def self.find_libys_path name = libys_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_paths ⇒ Object
Returns an array of library paths extracted from the LD_LIBRARY_PATH
environment variable (PATH on Windows).
If the environment variable is not set will return an array with
/usr/local/lib only.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yamlscript.rb', line 52 def self.ld_library_paths if windows? paths = ENV.fetch('PATH', '').split(File::PATH_SEPARATOR) home = ENV.fetch('USERPROFILE', ENV.fetch('HOME', '')) else paths = ENV.fetch('LD_LIBRARY_PATH', '').split(':') paths << '/usr/local/lib' home = ENV.fetch('HOME', '') end paths << home + '/.local/lib' end |
.libys_name ⇒ Object
42 43 44 45 46 |
# File 'lib/yamlscript.rb', line 42 def self.libys_name return 'libys.dll' if windows? "libys.#{extension}.#{YAMLSCRIPT_VERSION}" end |
.windows? ⇒ Boolean
25 26 27 |
# File 'lib/yamlscript.rb', line 25 def self.windows? RUBY_PLATFORM.match?(/mingw|mswin/) end |