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 |
Create a cached instance of the classpath (a LoadingClasspath).
# 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
Ask the cache for the classname and return it. Else delegate loading.
# 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