Class: Library
- Inherits:
-
Object
- Object
- Library
- Defined in:
- lib/picrate/library.rb
Overview
This class knows where to find picrate libraries
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#ppath ⇒ Object
readonly
Returns the value of attribute ppath.
Instance Method Summary collapse
- #add_binaries_to_classpath ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(name) ⇒ Library
constructor
A new instance of Library.
- #load_jars ⇒ Object
- #locate ⇒ Object
- #locate_installed_java ⇒ Object
- #locate_java ⇒ Object
- #native_binaries? ⇒ Boolean
- #ruby? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Library
Returns a new instance of Library.
11 12 13 14 |
# File 'lib/picrate/library.rb', line 11 def initialize(name) @name = name @ruby = true end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
9 10 11 |
# File 'lib/picrate/library.rb', line 9 def dir @dir end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/picrate/library.rb', line 9 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/picrate/library.rb', line 9 def path @path end |
#ppath ⇒ Object (readonly)
Returns the value of attribute ppath.
9 10 11 |
# File 'lib/picrate/library.rb', line 9 def ppath @ppath end |
Instance Method Details
#add_binaries_to_classpath ⇒ Object
68 69 70 71 72 |
# File 'lib/picrate/library.rb', line 68 def add_binaries_to_classpath native_loader = NativeLoader.new native_loader.add_native_path(ppath) true end |
#exist? ⇒ Boolean
47 48 49 |
# File 'lib/picrate/library.rb', line 47 def exist? path.exist? end |
#load_jars ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/picrate/library.rb', line 51 def load_jars Dir.glob("#{dir}/*.jar").sort.each do |jar| require jar end return true unless native_binaries? add_binaries_to_classpath end |
#locate ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/picrate/library.rb', line 16 def locate return if (@path = Pathname.new( File.join(Processing::SKETCH_ROOT, 'library', name, "#{name}.rb") )).exist? return if (@path = Pathname.new( File.join(PICRATE_ROOT, 'library', name, "#{name}.rb") )).exist? locate_java end |
#locate_installed_java ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/picrate/library.rb', line 34 def locate_installed_java unless dir.directory? @dir = Pathname.new( File.join(ENV['HOME'], '.picrate', 'libraries', name, 'library') ) end @path = dir.join(Pathname.new("#{name}.jar")) end |
#locate_java ⇒ Object
27 28 29 30 31 32 |
# File 'lib/picrate/library.rb', line 27 def locate_java @dir = Pathname.new( File.join(Processing::SKETCH_ROOT, 'library', name) ) locate_installed_java end |
#native_binaries? ⇒ Boolean
60 61 62 63 64 65 66 |
# File 'lib/picrate/library.rb', line 60 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
43 44 45 |
# File 'lib/picrate/library.rb', line 43 def ruby? path.extname == '.rb' end |