Class: Library

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

Overview

This class knows where to find JRubyArt libraries

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Library

Returns a new instance of Library.



12
13
14
15
# File 'lib/jruby_art/library.rb', line 12

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#ppathObject (readonly)

Returns the value of attribute ppath.



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

def ppath
  @ppath
end

Instance Method Details

#add_binaries_to_classpathObject



74
75
76
77
# File 'lib/jruby_art/library.rb', line 74

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

#exist?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/jruby_art/library.rb', line 53

def exist?
  path.exist?
end

#library_pathObject



45
46
47
# File 'lib/jruby_art/library.rb', line 45

def library_path
  Processing::RP_CONFIG.fetch('library_path', "#{ENV['HOME']}/.jruby_art")
end

#load_jarsObject



57
58
59
60
61
62
63
64
# File 'lib/jruby_art/library.rb', line 57

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

  add_binaries_to_classpath
end

#locateObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/jruby_art/library.rb', line 17

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

  locate_java
end

#locate_installed_javaObject



37
38
39
40
41
42
43
# File 'lib/jruby_art/library.rb', line 37

def locate_installed_java
  prefix = library_path
  @dir = Pathname.new(
    File.join(prefix, "libraries/#{name}/library")
  )
  @path = dir.join(Pathname.new("#{name}.jar"))
end

#locate_javaObject



28
29
30
31
32
33
34
35
# File 'lib/jruby_art/library.rb', line 28

def locate_java
  @dir = Pathname.new(
    File.join(SKETCH_ROOT, 'library', name)
  )
  return @path = dir.join(Pathname.new("#{name}.jar")) if dir.directory?

  locate_installed_java
end

#native_binaries?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'lib/jruby_art/library.rb', line 66

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)


49
50
51
# File 'lib/jruby_art/library.rb', line 49

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