Class: JavaClass::Dsl::CachingClasspath
- Includes:
- ClasspathAnalysers
- Defined in:
- lib/javaclass/dsl/caching_classpath.rb,
lib/javaclass/dsl/classpath_analysers.rb
Overview
A delegator classpath that caches loaded class files in a map by full qualified class names.
- Author
-
Peter Kofler
Instance Method Summary collapse
-
#initialize(classpath) ⇒ CachingClasspath
constructor
Create a cached instance of the classpath (a LoadingClasspath).
-
#load(classname) ⇒ Object
Ask the cache for the classname and return it.
-
#values(listed = nil, &filter) ⇒ Object
Load listed or all classes.
Methods included from Analyse::TransitiveDependencies
#transitive_dependencies_package, #transitive_dependency_tree
Methods included from Analyse::Dependencies
#external_types, #types, #used_types, #used_types_map
Constructor Details
#initialize(classpath) ⇒ CachingClasspath
Create a cached instance of the classpath (a LoadingClasspath).
11 12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#load(classname) ⇒ Object
Ask the cache for the classname and return it. Else delegate loading.
21 22 23 24 25 26 27 |
# 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 |
#values(listed = nil, &filter) ⇒ Object
Load listed or all classes. Duplicate method to use the cache of decorator.
30 31 32 33 |
# File 'lib/javaclass/dsl/caching_classpath.rb', line 30 def values(listed=nil, &filter) listed ||= names(&filter) listed.collect { |name| load(name) } end |