Class: Processing::LibraryLoader

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

Overview

Encapsulate library loader functionality as a class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLibraryLoader

Returns a new instance of LibraryLoader.



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

def initialize
  @loaded_libraries = Hash.new(false)
end

Instance Attribute Details

#libraryObject (readonly)

Returns the value of attribute library.



8
9
10
# File 'lib/jruby_art/library_loader.rb', line 8

def library
  @library
end

Instance Method Details

#library_loaded?(library_name) ⇒ Boolean

Detect if a library has been loaded (for conditional loading)

Returns:

  • (Boolean)


15
16
17
# File 'lib/jruby_art/library_loader.rb', line 15

def library_loaded?(library_name)
  @loaded_libraries[library_name.to_sym]
end

#load_jars(lib, name) ⇒ Object



43
44
45
46
# File 'lib/jruby_art/library_loader.rb', line 43

def load_jars(lib, name)
  lib.load_jars
  @loaded_libraries[name] = true
end

#load_libraries(*args) ⇒ Object Also known as: load_library

Load a list of Ruby or Java libraries (in that order) Usage: load_libraries :video, :video_event

If a library is put into a ‘library’ folder next to the sketch it will be used instead of the library that ships with vanilla processing (or ide installed), or JRubyArt.



24
25
26
27
28
29
30
# File 'lib/jruby_art/library_loader.rb', line 24

def load_libraries(*args)
  message = 'no such file to load -- %s'
  args.each do |lib|
    loaded = loader(lib)
    raise(LoadError.new, format(message, lib)) unless loaded
  end
end

#loader(name) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/jruby_art/library_loader.rb', line 33

def loader(name)
  return true if @loaded_libraries.include?(name)
  fname = name.to_s
  library = Library.new(fname)
  library.locate
  return require_library(library, name) if library.ruby?
  warn("Not found library: #{fname}") unless library.exist?
  load_jars(library, name)
end

#require_library(lib, name) ⇒ Object



48
49
50
# File 'lib/jruby_art/library_loader.rb', line 48

def require_library(lib, name)
  @loaded_libraries[name] = require lib.path
end