Class: Mbeditor::RiDefinitionService
- Inherits:
-
Object
- Object
- Mbeditor::RiDefinitionService
- Defined in:
- app/services/mbeditor/ri_definition_service.rb
Overview
Looks up Ruby core / gem method documentation using the ri CLI tool. Falls back silently if ri is unavailable or times out.
Returns an array in the same format as RubyDefinitionService:
[{ file: String, line: Integer, signature: String, comments: String }]
line is always 0 for ri results (no workspace file location). Results are cached in-process to avoid repeated subprocess overhead.
Constant Summary collapse
- TIMEOUT_SECONDS =
3- MAX_DESC_LINES =
3- PREFERRED_CLASSES =
When a method is defined on many classes, prefer these over the first-alphabetical class (e.g. prefer BasicObject#new over Addrinfo#new).
%w[BasicObject Object Kernel Module Class].freeze
Class Method Summary collapse
- .call(symbol) ⇒ Object
-
.clear_cache! ⇒ Object
Exposed for tests — clears the in-process cache.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(symbol) ⇒ RiDefinitionService
constructor
A new instance of RiDefinitionService.
Constructor Details
#initialize(symbol) ⇒ RiDefinitionService
Returns a new instance of RiDefinitionService.
42 43 44 |
# File 'app/services/mbeditor/ri_definition_service.rb', line 42 def initialize(symbol) @symbol = symbol end |
Class Method Details
.call(symbol) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'app/services/mbeditor/ri_definition_service.rb', line 27 def call(symbol) cached = @mutex.synchronize { @cache[symbol] } return cached unless cached.nil? result = new(symbol).call @mutex.synchronize { @cache[symbol] = result } result end |
.clear_cache! ⇒ Object
Exposed for tests — clears the in-process cache.
37 38 39 |
# File 'app/services/mbeditor/ri_definition_service.rb', line 37 def clear_cache! @mutex.synchronize { @cache.clear } end |
Instance Method Details
#call ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'app/services/mbeditor/ri_definition_service.rb', line 46 def call output = run_ri return [] if output.nil? || output.strip.empty? return [] if output.start_with?("Nothing known") parse(output) rescue StandardError [] end |