Class: Processing::LibraryLoader
- Inherits:
-
Object
- Object
- Processing::LibraryLoader
- Defined in:
- lib/picrate/library_loader.rb
Overview
Encapsulate library loader functionality as a class
Instance Attribute Summary collapse
-
#library ⇒ Object
readonly
Returns the value of attribute library.
Instance Method Summary collapse
-
#initialize ⇒ LibraryLoader
constructor
A new instance of LibraryLoader.
-
#library_loaded?(library_name) ⇒ Boolean
Detect if a library has been loaded (for conditional loading).
- #load_jars(lib, name) ⇒ Object
-
#load_libraries(*args) ⇒ Object
(also: #load_library)
Load a list of Ruby or Java libraries (in that order) Usage: load_libraries :video, :video_event.
- #loader(name) ⇒ Object
- #require_library(lib, name) ⇒ Object
Constructor Details
#initialize ⇒ LibraryLoader
Returns a new instance of LibraryLoader.
11 12 13 |
# File 'lib/picrate/library_loader.rb', line 11 def initialize @loaded_libraries = Hash.new(false) end |
Instance Attribute Details
#library ⇒ Object (readonly)
Returns the value of attribute library.
9 10 11 |
# File 'lib/picrate/library_loader.rb', line 9 def library @library end |
Instance Method Details
#library_loaded?(library_name) ⇒ Boolean
Detect if a library has been loaded (for conditional loading)
16 17 18 |
# File 'lib/picrate/library_loader.rb', line 16 def library_loaded?(library_name) @loaded_libraries[library_name.to_sym] end |
#load_jars(lib, name) ⇒ Object
46 47 48 49 |
# File 'lib/picrate/library_loader.rb', line 46 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 an installed picrate library.
25 26 27 28 29 30 31 |
# File 'lib/picrate/library_loader.rb', line 25 def load_libraries(*args) = 'no such file to load -- %s' args.each do |lib| loaded = loader(lib) raise(LoadError.new, format(, lib)) unless loaded end end |
#loader(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/picrate/library_loader.rb', line 34 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
51 52 53 |
# File 'lib/picrate/library_loader.rb', line 51 def require_library(lib, name) @loaded_libraries[name] = require lib.path end |