Class: Library

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

Overview

This class knows where to find propane libraries

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Library

Returns a new instance of Library.



9
10
11
12
# File 'lib/propane/library.rb', line 9

def initialize(name)
  @name = name
  @ruby = true
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#ppathObject (readonly)

Returns the value of attribute ppath.



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

def ppath
  @ppath
end

Instance Method Details

#add_binaries_to_classpathObject



64
65
66
67
68
# File 'lib/propane/library.rb', line 64

def add_binaries_to_classpath
  native_loader = NativeLoader.new
  native_loader.add_native_path(ppath)
  true
end

#exist?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/propane/library.rb', line 44

def exist?
  path.exist?
end

#load_jarsObject



48
49
50
51
52
53
54
# File 'lib/propane/library.rb', line 48

def load_jars
  Dir.glob("#{dir}/*.jar").each do |jar|
    require jar
  end
  return true unless native_binaries?
  add_binaries_to_classpath
end

#locateObject



14
15
16
17
18
19
20
21
22
# File 'lib/propane/library.rb', line 14

def locate
  return if (@path = Pathname.new(
    File.join(Propane::SKETCH_ROOT, 'library', name, "#{name}.rb")
  )).exist?
  return if (@path = Pathname.new(
    File.join(PROPANE_ROOT, 'library', name, "#{name}.rb")
  )).exist?
  locate_java
end

#locate_installed_javaObject



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

def locate_installed_java
  unless dir.directory?
    @dir = Pathname.new(
      File.join(ENV['HOME'], '.propane', 'libraries', name, 'library')
    )
  end
  @path = dir.join(Pathname.new("#{name}.jar"))
end

#locate_javaObject



24
25
26
27
28
29
# File 'lib/propane/library.rb', line 24

def locate_java
  @dir = Pathname.new(
    File.join(Propane::SKETCH_ROOT, 'library', name)
  )
  locate_installed_java
end

#native_binaries?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'lib/propane/library.rb', line 56

def native_binaries?
  native_folder = NativeFolder.new
  native = native_folder.name
  @ppath = File.join(dir, native)
  File.directory?(ppath) &&
    !Dir.glob(File.join(ppath, native_folder.extension)).empty?
end

#ruby?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/propane/library.rb', line 40

def ruby?
  path.extname == '.rb'
end