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 Attribute Summary collapse
- #pins ⇒ Array<Solargraph::Pin::Base> readonly
Instance Method Summary collapse
- #block_pins ⇒ Enumerable<Pin::Block>
- #cacheable_pins ⇒ Object
- #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(fqns) ⇒ String?
- #get_symbols ⇒ Enumerable<Solargraph::Pin::Base>
-
#initialize(pins = []) ⇒ 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::Base>
- #namespaces ⇒ Set<String>
- #pins_by_class(klass) ⇒ Set<T>
Constructor Details
#initialize(pins = []) ⇒ Store
Returns a new instance of Store.
14 15 16 17 |
# File 'lib/solargraph/api_map/store.rb', line 14 def initialize pins = [] @pins = pins index end |
Instance Attribute Details
#pins ⇒ Array<Solargraph::Pin::Base> (readonly)
11 12 13 |
# File 'lib/solargraph/api_map/store.rb', line 11 def pins @pins end |
Instance Method Details
#block_pins ⇒ Enumerable<Pin::Block>
142 143 144 |
# File 'lib/solargraph/api_map/store.rb', line 142 def block_pins pins_by_class(Pin::Block) end |
#cacheable_pins ⇒ Object
72 73 74 |
# File 'lib/solargraph/api_map/store.rb', line 72 def cacheable_pins @cacheable_pins ||= pins_by_class(Pin::Namespace) + pins_by_class(Pin::Constant) + pins_by_class(Pin::Method) + pins_by_class(Pin::Reference) end |
#domains(fqns) ⇒ Array<String>
119 120 121 122 123 124 125 |
# File 'lib/solargraph/api_map/store.rb', line 119 def domains(fqns) result = [] fqns_pins(fqns).each do |nspin| result.concat nspin.domains end result end |
#fqns_pins(fqns) ⇒ Array<Solargraph::Pin::Namespace>
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/solargraph/api_map/store.rb', line 162 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>
87 88 89 |
# File 'lib/solargraph/api_map/store.rb', line 87 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>
22 23 24 25 26 |
# File 'lib/solargraph/api_map/store.rb', line 22 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>
62 63 64 |
# File 'lib/solargraph/api_map/store.rb', line 62 def get_extends fqns extend_references[fqns] || [] end |
#get_includes(fqns) ⇒ Array<String>
50 51 52 |
# File 'lib/solargraph/api_map/store.rb', line 50 def get_includes fqns include_references[fqns] || [] end |
#get_instance_variables(fqns, scope = :instance) ⇒ Enumerable<Solargraph::Pin::Base>
79 80 81 82 83 |
# File 'lib/solargraph/api_map/store.rb', line 79 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>
32 33 34 35 36 |
# File 'lib/solargraph/api_map/store.rb', line 32 def get_methods fqns, scope: :instance, visibility: [:public] namespace_children(fqns).select do |pin| pin.is_a?(Pin::Method) && pin.scope == scope && visibility.include?(pin.visibility) end end |
#get_path_pins(path) ⇒ Array<Solargraph::Pin::Base>
68 69 70 |
# File 'lib/solargraph/api_map/store.rb', line 68 def get_path_pins path path_pin_hash[path] || [] end |
#get_prepends(fqns) ⇒ Array<String>
56 57 58 |
# File 'lib/solargraph/api_map/store.rb', line 56 def get_prepends fqns prepend_references[fqns] || [] end |
#get_superclass(fqns) ⇒ String?
40 41 42 43 44 45 46 |
# File 'lib/solargraph/api_map/store.rb', line 40 def get_superclass fqns raise "Do not prefix fully qualified namespaces with '::' - #{fqns.inspect}" if fqns.start_with?('::') return superclass_references[fqns].first if superclass_references.key?(fqns) return 'Object' if fqns != 'BasicObject' && namespace_exists?(fqns) return 'Object' if fqns == 'Boolean' nil end |
#get_symbols ⇒ Enumerable<Solargraph::Pin::Base>
92 93 94 |
# File 'lib/solargraph/api_map/store.rb', line 92 def get_symbols symbols.uniq(&:name) end |
#inspect ⇒ Object
146 147 148 149 |
# File 'lib/solargraph/api_map/store.rb', line 146 def inspect # Avoid insane dumps in specs to_s end |
#method_pins ⇒ Enumerable<Solargraph::Pin::Method>
113 114 115 |
# File 'lib/solargraph/api_map/store.rb', line 113 def method_pins pins_by_class(Solargraph::Pin::Method) end |
#named_macros ⇒ Hash{String => YARD::Tags::MacroDirective}
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/solargraph/api_map/store.rb', line 128 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
98 99 100 |
# File 'lib/solargraph/api_map/store.rb', line 98 def namespace_exists?(fqns) fqns_pins(fqns).any? end |
#namespace_pins ⇒ Enumerable<Solargraph::Pin::Base>
108 109 110 |
# File 'lib/solargraph/api_map/store.rb', line 108 def namespace_pins pins_by_class(Solargraph::Pin::Namespace) end |
#namespaces ⇒ Set<String>
103 104 105 |
# File 'lib/solargraph/api_map/store.rb', line 103 def namespaces @namespaces ||= Set.new end |
#pins_by_class(klass) ⇒ Set<T>
154 155 156 157 158 |
# File 'lib/solargraph/api_map/store.rb', line 154 def pins_by_class klass # @type [Set<Solargraph::Pin::Base>] s = Set.new @pin_select_cache[klass] ||= @pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass } end |