Class: Solargraph::ApiMap::Store
- Inherits:
-
Object
- Object
- Solargraph::ApiMap::Store
- Defined in:
- lib/solargraph/api_map/store.rb
Overview
Queryable collection of Pins representing a Workspace, gems and the Ruby core.
Instance Method Summary collapse
- #block_pins ⇒ Enumerable<Pin::Block>
- #domains(fqns) ⇒ Array<String>
- #fqns_pins(fqns) ⇒ Array<Solargraph::Pin::Namespace>
- #get_class_variables(fqns) ⇒ Enumerable<Solargraph::Pin::Base>
- #get_constants(fqns, visibility = [:public]) ⇒ Enumerable<Solargraph::Pin::Base>
- #get_extends(fqns) ⇒ Array<String>
- #get_includes(fqns) ⇒ Array<String>
- #get_instance_variables(fqns, scope = :instance) ⇒ Enumerable<Solargraph::Pin::Base>
- #get_methods(fqns, scope: :instance, visibility: [:public]) ⇒ Enumerable<Solargraph::Pin::Method>
- #get_path_pins(path) ⇒ Array<Solargraph::Pin::Base>
- #get_prepends(fqns) ⇒ Array<String>
- #get_superclass(fq_tag) ⇒ String?
- #get_symbols ⇒ Enumerable<Solargraph::Pin::Base>
-
#initialize(*pinsets) ⇒ Store
constructor
A new instance of Store.
- #inspect ⇒ Object
- #method_pins ⇒ Enumerable<Solargraph::Pin::Method>
- #named_macros ⇒ Hash{String => YARD::Tags::MacroDirective}
- #namespace_exists?(fqns) ⇒ Boolean
- #namespace_pins ⇒ Enumerable<Solargraph::Pin::Namespace>
- #namespaces ⇒ Set<String>
- #pins ⇒ Array<Solargraph::Pin::Base>
- #pins_by_class(klass) ⇒ Set<generic<T>>
- #to_s ⇒ Object
-
#update(*pinsets) ⇒ Boolean
True if the index was updated.
Constructor Details
#initialize(*pinsets) ⇒ Store
10 11 12 |
# File 'lib/solargraph/api_map/store.rb', line 10 def initialize *pinsets catalog pinsets end |
Instance Method Details
#block_pins ⇒ Enumerable<Pin::Block>
175 176 177 |
# File 'lib/solargraph/api_map/store.rb', line 175 def block_pins pins_by_class(Pin::Block) end |
#domains(fqns) ⇒ Array<String>
152 153 154 155 156 157 158 |
# File 'lib/solargraph/api_map/store.rb', line 152 def domains(fqns) result = [] fqns_pins(fqns).each do |nspin| result.concat nspin.domains end result end |
#fqns_pins(fqns) ⇒ Array<Solargraph::Pin::Namespace>
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/solargraph/api_map/store.rb', line 188 def fqns_pins fqns return [] if fqns.nil? if fqns.include?('::') parts = fqns.split('::') name = parts.pop base = parts.join('::') else base = '' name = fqns end fqns_pins_map[[base, name]] end |
#get_class_variables(fqns) ⇒ Enumerable<Solargraph::Pin::Base>
120 121 122 |
# File 'lib/solargraph/api_map/store.rb', line 120 def get_class_variables(fqns) namespace_children(fqns).select { |pin| pin.is_a?(Pin::ClassVariable)} end |
#get_constants(fqns, visibility = [:public]) ⇒ Enumerable<Solargraph::Pin::Base>
53 54 55 56 57 |
# File 'lib/solargraph/api_map/store.rb', line 53 def get_constants fqns, visibility = [:public] namespace_children(fqns).select { |pin| !pin.name.empty? && (pin.is_a?(Pin::Namespace) || pin.is_a?(Pin::Constant)) && visibility.include?(pin.visibility) } end |
#get_extends(fqns) ⇒ Array<String>
99 100 101 |
# File 'lib/solargraph/api_map/store.rb', line 99 def get_extends fqns extend_references[fqns] || [] end |
#get_includes(fqns) ⇒ Array<String>
87 88 89 |
# File 'lib/solargraph/api_map/store.rb', line 87 def get_includes fqns include_references[fqns] || [] end |
#get_instance_variables(fqns, scope = :instance) ⇒ Enumerable<Solargraph::Pin::Base>
112 113 114 115 116 |
# File 'lib/solargraph/api_map/store.rb', line 112 def get_instance_variables(fqns, scope = :instance) all_instance_variables.select { |pin| pin.binder.namespace == fqns && pin.binder.scope == scope } end |
#get_methods(fqns, scope: :instance, visibility: [:public]) ⇒ Enumerable<Solargraph::Pin::Method>
63 64 65 66 67 68 |
# File 'lib/solargraph/api_map/store.rb', line 63 def get_methods fqns, scope: :instance, visibility: [:public] all_pins = namespace_children(fqns).select do |pin| pin.is_a?(Pin::Method) && pin.scope == scope && visibility.include?(pin.visibility) end GemPins.combine_method_pins_by_path(all_pins) end |
#get_path_pins(path) ⇒ Array<Solargraph::Pin::Base>
105 106 107 |
# File 'lib/solargraph/api_map/store.rb', line 105 def get_path_pins path index.path_pin_hash[path] end |
#get_prepends(fqns) ⇒ Array<String>
93 94 95 |
# File 'lib/solargraph/api_map/store.rb', line 93 def get_prepends fqns prepend_references[fqns] || [] end |
#get_superclass(fq_tag) ⇒ String?
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/solargraph/api_map/store.rb', line 72 def get_superclass fq_tag raise "Do not prefix fully qualified tags with '::' - #{fq_tag.inspect}" if fq_tag.start_with?('::') sub = ComplexType.parse(fq_tag) fqns = sub.namespace return superclass_references[fq_tag].first if superclass_references.key?(fq_tag) return superclass_references[fqns].first if superclass_references.key?(fqns) return 'Object' if fqns != 'BasicObject' && namespace_exists?(fqns) return 'Object' if fqns == 'Boolean' simplified_literal_name = ComplexType.parse("#{fqns}").simplify_literals.name return simplified_literal_name if simplified_literal_name != fqns nil end |
#get_symbols ⇒ Enumerable<Solargraph::Pin::Base>
125 126 127 |
# File 'lib/solargraph/api_map/store.rb', line 125 def get_symbols symbols.uniq(&:name) end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/solargraph/api_map/store.rb', line 46 def inspect to_s end |
#method_pins ⇒ Enumerable<Solargraph::Pin::Method>
146 147 148 |
# File 'lib/solargraph/api_map/store.rb', line 146 def method_pins pins_by_class(Solargraph::Pin::Method) end |
#named_macros ⇒ Hash{String => YARD::Tags::MacroDirective}
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/solargraph/api_map/store.rb', line 161 def named_macros @named_macros ||= begin result = {} pins.each do |pin| pin.macros.select{|m| m.tag.tag_name == 'macro' && !m.tag.text.empty? }.each do |macro| next if macro.tag.name.nil? || macro.tag.name.empty? result[macro.tag.name] = macro end end result end end |
#namespace_exists?(fqns) ⇒ Boolean
131 132 133 |
# File 'lib/solargraph/api_map/store.rb', line 131 def namespace_exists?(fqns) fqns_pins(fqns).any? end |
#namespace_pins ⇒ Enumerable<Solargraph::Pin::Namespace>
141 142 143 |
# File 'lib/solargraph/api_map/store.rb', line 141 def namespace_pins pins_by_class(Solargraph::Pin::Namespace) end |
#namespaces ⇒ Set<String>
136 137 138 |
# File 'lib/solargraph/api_map/store.rb', line 136 def namespaces index.namespaces end |
#pins ⇒ Array<Solargraph::Pin::Base>
15 16 17 |
# File 'lib/solargraph/api_map/store.rb', line 15 def pins index.pins end |
#pins_by_class(klass) ⇒ Set<generic<T>>
182 183 184 |
# File 'lib/solargraph/api_map/store.rb', line 182 def pins_by_class klass index.pins_by_class klass end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/solargraph/api_map/store.rb', line 42 def to_s self.class.to_s end |
#update(*pinsets) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/solargraph/api_map/store.rb', line 21 def update *pinsets return catalog(pinsets) if pinsets.length != @pinsets.length changed = pinsets.find_index.with_index { |pinset, idx| @pinsets[idx] != pinset } return false unless changed # @todo Fix this map @fqns_pins_map = nil return catalog(pinsets) if changed == 0 pinsets[changed..].each_with_index do |pins, idx| @pinsets[changed + idx] = pins @indexes[changed + idx] = if pins.empty? @indexes[changed + idx - 1] else @indexes[changed + idx - 1].merge(pins) end end true end |