Class: Rubycli::DocumentationRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycli/documentation_registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(environment:) ⇒ DocumentationRegistry

Returns a new instance of DocumentationRegistry.



10
11
12
13
14
15
# File 'lib/rubycli/documentation_registry.rb', line 10

def initialize(environment:)
  @environment = environment
  @metadata_cache = {}
  @comment_extractor = Documentation::CommentExtractor.new
  @parser = Documentation::MetadataParser.new(environment: environment)
end

Instance Method Details

#metadata_for(method_obj) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rubycli/documentation_registry.rb', line 17

def (method_obj)
  return  unless method_obj

  location = method_obj.source_location
  return  unless location

  cache_key = [location[0], location[1], @environment.doc_check_mode?, @environment.allow_param_comments?]
  return deep_dup(@metadata_cache[cache_key]) if @metadata_cache.key?(cache_key)

  comment_lines = @comment_extractor.extract(location[0], location[1])
   = @parser.parse(comment_lines, method_obj)
  @metadata_cache[cache_key] = 
  deep_dup()
rescue Errno::ENOENT
  
end

#reset!Object



34
35
36
37
38
# File 'lib/rubycli/documentation_registry.rb', line 34

def reset!
  @metadata_cache.clear
  @comment_extractor.reset!
  @parser.reset_type_dictionary_cache! if @parser.respond_to?(:reset_type_dictionary_cache!)
end