Class: NativeFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/propane/native_folder.rb

Overview

Utility to load native binaries on Java CLASSPATH

Constant Summary collapse

WIN_FORMAT =
'windows%d'
LINUX_FORMAT =
'linux%d'
WIN_PATTERNS =
[
  /bccwin/i,
  /cygwin/i,
  /djgpp/i,
  /ming/i,
  /mswin/i,
  /wince/i
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNativeFolder

Returns a new instance of NativeFolder.



20
21
22
23
# File 'lib/propane/native_folder.rb', line 20

def initialize
  @os = RbConfig::CONFIG['host_os'].downcase
  @bit = /64/.match?(java.lang.System.get_property('os.arch')) ? 64 : 32
end

Instance Attribute Details

#bitObject (readonly)

Returns the value of attribute bit.



7
8
9
# File 'lib/propane/native_folder.rb', line 7

def bit
  @bit
end

#osObject (readonly)

Returns the value of attribute os.



7
8
9
# File 'lib/propane/native_folder.rb', line 7

def os
  @os
end

Instance Method Details

#extensionObject



33
34
35
36
37
38
# File 'lib/propane/native_folder.rb', line 33

def extension
  return '*.so' if /linux/.match?(os)
  return '*.dll' if WIN_PATTERNS.any? { |pat| pat.match?(os) }

  '*.dylib' # MacOS
end

#nameObject



25
26
27
28
29
30
31
# File 'lib/propane/native_folder.rb', line 25

def name
  return 'macosx' if /darwin|mac/.match?(os)
  return format(LINUX_FORMAT, bit) if /linux/.match?(os)
  return format(WIN_FORMAT, bit) if WIN_PATTERNS.any? { |pat| pat.match?(os) }

  raise 'Unsupported Architecture'
end