Class: Solargraph::YardMap
- Inherits:
-
Object
- Object
- Solargraph::YardMap
show all
- Defined in:
- lib/solargraph/yard_map.rb,
lib/solargraph/yard_map/cache.rb,
lib/solargraph/yard_map/mapper.rb,
lib/solargraph/yard_map/core_gen.rb,
lib/solargraph/yard_map/core_docs.rb,
lib/solargraph/yard_map/rdoc_to_yard.rb
Overview
The YardMap provides access to YARD documentation for the Ruby core, the stdlib, and gems.
Defined Under Namespace
Modules: CoreDocs, CoreGen, RdocToYard
Classes: Cache, Mapper
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(required: [], gemset: {}, with_dependencies: true) ⇒ YardMap
Returns a new instance of YardMap.
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/solargraph/yard_map.rb', line 50
def initialize(required: [], gemset: {}, with_dependencies: true)
@required = required.clone
@with_dependencies = with_dependencies
@gem_paths = {}
@stdlib_namespaces = []
@gemset = gemset
@source_gems = []
process_requires
yardocs.uniq!
@pin_select_cache = {}
end
|
Instance Attribute Details
#gemset ⇒ Hash{String => String}
A hash of gem names and the version numbers to include in the map.
45
46
47
|
# File 'lib/solargraph/yard_map.rb', line 45
def gemset
@gemset
end
|
#required ⇒ Array<String>
37
38
39
|
# File 'lib/solargraph/yard_map.rb', line 37
def required
@required
end
|
#with_dependencies=(value) ⇒ Boolean
40
41
42
|
# File 'lib/solargraph/yard_map.rb', line 40
def with_dependencies=(value)
@with_dependencies = value
end
|
Instance Method Details
#change(new_requires, new_gemset, source_gems = []) ⇒ Boolean
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/solargraph/yard_map.rb', line 76
def change new_requires, new_gemset, source_gems = []
if new_requires.uniq.sort == required.uniq.sort && new_gemset == gemset && @source_gems.uniq.sort == source_gems.uniq.sort
false
else
required.clear
required.concat new_requires
@gemset = new_gemset
@source_gems = source_gems
process_requires
@rebindable_method_names = nil
@pin_class_hash = nil
@pin_select_cache = {}
true
end
end
|
126
127
128
129
|
# File 'lib/solargraph/yard_map.rb', line 126
def core_pins
@@core_pins ||= load_core_pins
end
|
#load_yardoc(y) ⇒ YARD::Registry
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/solargraph/yard_map.rb', line 113
def load_yardoc y
if y.is_a?(Array)
YARD::Registry.load y, true
else
YARD::Registry.load! y
end
rescue StandardError => e
Solargraph::Logging.logger.warn "Error loading yardoc '#{y}' #{e.class} #{e.message}"
yardocs.delete y
nil
end
|
133
134
135
|
# File 'lib/solargraph/yard_map.rb', line 133
def path_pin path
pins.select{ |p| p.path == path }.first
end
|
64
65
66
|
# File 'lib/solargraph/yard_map.rb', line 64
def pins
@pins ||= []
end
|
#rebindable_method_names ⇒ Set<String>
93
94
95
96
97
98
99
|
# File 'lib/solargraph/yard_map.rb', line 93
def rebindable_method_names
@rebindable_method_names ||= pins_by_class(Pin::Method)
.select { |pin| pin. && pin..include?('@yieldself') }
.map(&:name)
.concat(['instance_eval', 'instance_exec', 'class_eval', 'class_exec', 'module_eval', 'module_exec'])
.to_set
end
|
#require_reference(path) ⇒ Location
Get the location of a file referenced by a require path.
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/solargraph/yard_map.rb', line 141
def require_reference path
spec = spec_for_require(path)
spec.full_require_paths.each do |rp|
file = File.join(rp, "#{path}.rb")
next unless File.file?(file)
return Solargraph::Location.new(file, Solargraph::Range.from_to(0, 0, 0, 0))
end
nil
rescue Gem::LoadError
nil
end
|
#stdlib_paths ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/solargraph/yard_map.rb', line 21
def stdlib_paths
@@stdlib_paths ||= begin
result = {}
YARD::Registry.load! CoreDocs.yardoc_stdlib_file
YARD::Registry.all.each do |co|
next if co.file.nil?
path = co.file.sub(/^(ext|lib)\//, '').sub(/\.(rb|c)$/, '')
base = path.split('/').first
result[base] ||= []
result[base].push co
end
result
end
end
|
#unresolved_requires ⇒ Array<String>
107
108
109
|
# File 'lib/solargraph/yard_map.rb', line 107
def unresolved_requires
@unresolved_requires ||= []
end
|
#with_dependencies? ⇒ Boolean
68
69
70
71
|
# File 'lib/solargraph/yard_map.rb', line 68
def with_dependencies?
@with_dependencies ||= true unless @with_dependencies == false
@with_dependencies
end
|
#yardocs ⇒ Array<String>
102
103
104
|
# File 'lib/solargraph/yard_map.rb', line 102
def yardocs
@yardocs ||= []
end
|