class Rutie

Public Class Methods

new(project_name, **opts) click to toggle source
# File lib/rutie.rb, line 2
def initialize(project_name, **opts)
  @os = opts.fetch(:os) { nil } # for testing purposes

  @project_name = ProjectName.new(project_name)
  @lib_prefix = opts.fetch(:lib_prefix) { set_prefix }
  @lib_suffix = opts.fetch(:lib_suffix) { set_suffix }
  @release = opts.fetch(:release) { 'release' }
  @full_lib_path = opts.fetch(:lib_path) { nil }
end

Public Instance Methods

ffi_library(dir) click to toggle source
# File lib/rutie.rb, line 12
def ffi_library(dir)
  file = [ @lib_prefix, @project_name, '.', @lib_suffix ]

  File.join(lib_path(dir), file.join())
end
init(c_init_method_name, dir) click to toggle source
# File lib/rutie.rb, line 18
def init(c_init_method_name, dir)
  require 'fiddle'

  Fiddle::Function.new(Fiddle.dlopen(ffi_library dir)[c_init_method_name], [], Fiddle::TYPE_VOIDP).call
end

Private Instance Methods

host_os() click to toggle source
# File lib/rutie.rb, line 47
def host_os
  @os || RbConfig::CONFIG['host_os'].downcase
end
lib_path(dir) click to toggle source
# File lib/rutie.rb, line 25
def lib_path(dir)
  path = @full_lib_path || "../target/#{@release}"

  File.expand_path(path, dir)
end
operating_system() click to toggle source
# File lib/rutie.rb, line 51
def operating_system
  case host_os()
  when /linux|bsd|solaris/ then 'linux'
  when /darwin/ then 'darwin'
  when /mingw|mswin/ then 'windows'
  else host_os()
  end
end
set_prefix() click to toggle source
# File lib/rutie.rb, line 31
def set_prefix
  case operating_system()
  when /windows/ then ''
  when /cygwin/ then 'cyg'
  else 'lib'
  end
end
set_suffix() click to toggle source
# File lib/rutie.rb, line 39
def set_suffix
  case operating_system()
  when /darwin/ then 'dylib'
  when /windows|cygwin/ then 'dll'
  else 'so'
  end
end