Sha256: 371d8f88dc971a3124ad885a5b2e6cb6505bb7fb1aaf6c3c0a4c5452f46a674e

Contents?: true

Size: 1.43 KB

Versions: 22

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: false

# The processing wrapper module
module Processing
  require_relative 'library'

  # Encapsulate library loader functionality as a class
  class LibraryLoader
    attr_reader :library

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

    # Detect if a library has been loaded (for conditional loading)
    def library_loaded?(library_name)
      @loaded_libraries[library_name.to_sym]
    end

    # 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.
    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
    alias load_library load_libraries

    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

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

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

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
picrate-1.3.0-java lib/picrate/library_loader.rb
picrate-1.2.4-java lib/picrate/library_loader.rb
picrate-1.2.3-java lib/picrate/library_loader.rb
picrate-1.2.2-java lib/picrate/library_loader.rb
picrate-1.2.1-java lib/picrate/library_loader.rb
picrate-1.2.0-java lib/picrate/library_loader.rb
picrate-1.1.0-java lib/picrate/library_loader.rb
picrate-1.0.0-java lib/picrate/library_loader.rb
picrate-0.9.0-java lib/picrate/library_loader.rb
picrate-0.8.0-java lib/picrate/library_loader.rb
picrate-0.7.0-java lib/picrate/library_loader.rb
picrate-0.6.0-java lib/picrate/library_loader.rb
picrate-0.5.0-java lib/picrate/library_loader.rb
picrate-0.4.3-java lib/picrate/library_loader.rb
picrate-0.4.2-java lib/picrate/library_loader.rb
picrate-0.4.1-java lib/picrate/library_loader.rb
picrate-0.4.0-java lib/picrate/library_loader.rb
picrate-0.3.0-java lib/picrate/library_loader.rb
picrate-0.2.0-java lib/picrate/library_loader.rb
picrate-0.1.0-java lib/picrate/library_loader.rb