Class: DepsGrapher::SourceCache
- Inherits:
-
Object
- Object
- DepsGrapher::SourceCache
- Includes:
- Logging
- Defined in:
- lib/deps_grapher/source_cache.rb,
lib/deps_grapher/source_cache/registry.rb,
lib/deps_grapher/source_cache/class_name_extractor.rb
Defined Under Namespace
Modules: Registry Classes: ClassNameExtractor
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, source) ⇒ SourceCache
constructor
A new instance of SourceCache.
- #register! ⇒ Object
Methods included from Logging
#error, #info, #verbose, #warn
Constructor Details
#initialize(name, source) ⇒ SourceCache
Returns a new instance of SourceCache.
15 16 17 18 19 20 21 |
# File 'lib/deps_grapher/source_cache.rb', line 15 def initialize(name, source) @name = name @source = source @root = @source.root @cache_by_const_name = {} @cache_by_location = {} end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
13 14 15 |
# File 'lib/deps_grapher/source_cache.rb', line 13 def root @root end |
Class Method Details
.register!(name, source) ⇒ Object
8 9 10 |
# File 'lib/deps_grapher/source_cache.rb', line 8 def register!(name, source) new(name, source).register! end |
Instance Method Details
#register! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/deps_grapher/source_cache.rb', line 23 def register! class_name_extractor = ClassNameExtractor.new do |class_name, location| @cache_by_const_name[class_name] = location @cache_by_location[location] ||= class_name end verbose { "Collecting `#{@name}` layer by #{@source}" } start = Time.now @source.files.each do |file| class_name_extractor.extract! file end info do "Found #{@cache_by_const_name.size} modules/classes, #{@cache_by_location.size} locations in `#{@name}` layer (#{Time.now - start} sec)" end verbose { "" } Registry.register @cache_by_const_name, @cache_by_location ClassNameExtractor.cache.clear end |