Class JavaClass::Dsl::CachingClasspath
In: lib/javaclass/dsl/caching_classpath.rb
lib/javaclass/dsl/classpath_analysers.rb
Parent: SimpleDelegator

A delegator classpath that caches loaded class files in a map by full qualified class names.

Author:Peter Kofler

Methods

load   new   values  

Included Modules

ClasspathAnalysers

Public Class methods

Create a cached instance of the classpath (a LoadingClasspath).

[Source]

# File lib/javaclass/dsl/caching_classpath.rb, line 11
      def initialize(classpath)
        unless classpath.respond_to? :load 
          raise ArgumentError, "wrong type of delegatee #{classpath.class}"
        end
        @classpath = classpath
        @cache = Hash.new # full_name (String) => ClassEntryHeader
        super(classpath)
      end

Public Instance methods

Ask the cache for the classname and return it. Else delegate loading.

[Source]

# File lib/javaclass/dsl/caching_classpath.rb, line 21
      def load(classname)
        key = classname.to_javaname.full_name
        if !@cache.include?(key)
          @cache[key] = @classpath.load(classname)
        end
        @cache[key]
      end

Load listed or all classes. Duplicate method to use the cache of decorator.

[Source]

# File lib/javaclass/dsl/caching_classpath.rb, line 30
      def values(listed=nil, &filter)
        listed ||= names(&filter)
        listed.collect { |name| load(name) }
      end

[Validate]