Class JavaClass::Classpath::FolderClasspath
In: lib/javaclass/classpath/folder_classpath.rb
Parent: FileClasspath

Abstraction of a folder on the CLASSPATH. This is a leaf in the classpath tree.

Author:Peter Kofler

Methods

Public Class methods

Create a classpath with this folder .

[Source]

# File lib/javaclass/classpath/folder_classpath.rb, line 18
      def initialize(folder)
        super(folder)
        unless FolderClasspath::valid_location?(folder)
          raise IOError, "folder #{folder} not found/no folder"
        end
        @folder = folder
        init_classes
      end

Check if the file is a valid location for a folder classpath.

[Source]

# File lib/javaclass/classpath/folder_classpath.rb, line 13
      def self.valid_location?(file)
        FileTest.exist?(file) && FileTest.directory?(file) 
      end

Public Instance methods

Return the number of classes in this folder.

[Source]

# File lib/javaclass/classpath/folder_classpath.rb, line 51
      def count
        @class_names.size
      end

Return if classname is included in this folder.

[Source]

# File lib/javaclass/classpath/folder_classpath.rb, line 37
      def includes?(classname)
        @class_lookup[to_key(classname).file_name] 
      end

Load the binary data of the file name or class name classname from this folder.

[Source]

# File lib/javaclass/classpath/folder_classpath.rb, line 42
      def load_binary(classname)
        key = to_key(classname)
        unless includes?(key)
          raise ClassNotFoundError.new(key, @folder)
        end
        File.open(File.join(@folder, key), 'rb') { |io| io.read.freeze }
      end

Return the list of class names found in this folder. An additional block is used as filter on class names.

[Source]

# File lib/javaclass/classpath/folder_classpath.rb, line 28
      def names(&filter)
        if block_given?
          @class_names.find_all { |n| filter.call(n) }
        else
          @class_names.dup
        end
      end

[Validate]