Class: Solargraph::ApiMap::Store
- Inherits:
-
Object
- Object
- Solargraph::ApiMap::Store
- Defined in:
- lib/solargraph/api_map/store.rb
Instance Attribute Summary collapse
- #pins ⇒ Array<Solargraph::Pin::Base> readonly
Instance Method Summary collapse
- #block_pins ⇒ Array<Pin::Block>
- #domains(fqns) ⇒ Array<String>
- #get_class_variables(fqns) ⇒ Array<Solargraph::Pin::Base>
- #get_constants(fqns, visibility = [:public]) ⇒ Array<Solargraph::Pin::Base>
- #get_extends(fqns) ⇒ Array<String>
- #get_includes(fqns) ⇒ Array<String>
- #get_instance_variables(fqns, scope = :instance) ⇒ Array<Solargraph::Pin::Base>
- #get_methods(fqns, scope: :instance, visibility: [:public]) ⇒ Array<Solargraph::Pin::Base>
- #get_path_pins(path) ⇒ Array<Solargraph::Pin::Base>
- #get_prepends(fqns) ⇒ Array<String>
- #get_superclass(fqns) ⇒ String?
- #get_symbols ⇒ Array<Solargraph::Pin::Base>
-
#initialize(pins = []) ⇒ Store
constructor
A new instance of Store.
- #inspect ⇒ Object
- #method_pins ⇒ Array<Solargraph::Pin::Method>
- #named_macros ⇒ Hash
- #namespace_exists?(fqns) ⇒ Boolean
- #namespace_pins ⇒ Array<Solargraph::Pin::Base>
- #namespaces ⇒ Set<String>
- #pins_by_class(klass) ⇒ Array<Solargraph::Pin::Base>
Constructor Details
#initialize(pins = []) ⇒ Store
Returns a new instance of Store.
12 13 14 15 |
# File 'lib/solargraph/api_map/store.rb', line 12 def initialize pins = [] @pins = pins index end |
Instance Attribute Details
#pins ⇒ Array<Solargraph::Pin::Base> (readonly)
9 10 11 |
# File 'lib/solargraph/api_map/store.rb', line 9 def pins @pins end |
Instance Method Details
#block_pins ⇒ Array<Pin::Block>
135 136 137 |
# File 'lib/solargraph/api_map/store.rb', line 135 def block_pins pins_by_class(Pin::Block) end |
#domains(fqns) ⇒ Array<String>
112 113 114 115 116 117 118 |
# File 'lib/solargraph/api_map/store.rb', line 112 def domains(fqns) result = [] fqns_pins(fqns).each do |nspin| result.concat nspin.domains end result end |
#get_class_variables(fqns) ⇒ Array<Solargraph::Pin::Base>
80 81 82 |
# File 'lib/solargraph/api_map/store.rb', line 80 def get_class_variables(fqns) namespace_children(fqns).select{|pin| pin.is_a?(Pin::ClassVariable)} end |
#get_constants(fqns, visibility = [:public]) ⇒ Array<Solargraph::Pin::Base>
20 21 22 23 24 |
# File 'lib/solargraph/api_map/store.rb', line 20 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>
59 60 61 |
# File 'lib/solargraph/api_map/store.rb', line 59 def get_extends fqns extend_references[fqns] || [] end |
#get_includes(fqns) ⇒ Array<String>
47 48 49 |
# File 'lib/solargraph/api_map/store.rb', line 47 def get_includes fqns include_references[fqns] || [] end |
#get_instance_variables(fqns, scope = :instance) ⇒ Array<Solargraph::Pin::Base>
72 73 74 75 76 |
# File 'lib/solargraph/api_map/store.rb', line 72 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]) ⇒ Array<Solargraph::Pin::Base>
30 31 32 33 34 |
# File 'lib/solargraph/api_map/store.rb', line 30 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>
65 66 67 |
# File 'lib/solargraph/api_map/store.rb', line 65 def get_path_pins path path_pin_hash[path] || [] end |
#get_prepends(fqns) ⇒ Array<String>
53 54 55 |
# File 'lib/solargraph/api_map/store.rb', line 53 def get_prepends fqns prepend_references[fqns] || [] end |
#get_superclass(fqns) ⇒ String?
38 39 40 41 42 43 |
# File 'lib/solargraph/api_map/store.rb', line 38 def get_superclass fqns 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 ⇒ Array<Solargraph::Pin::Base>
85 86 87 |
# File 'lib/solargraph/api_map/store.rb', line 85 def get_symbols symbols.uniq(&:name) end |
#inspect ⇒ Object
139 140 141 142 |
# File 'lib/solargraph/api_map/store.rb', line 139 def inspect # Avoid insane dumps in specs to_s end |
#method_pins ⇒ Array<Solargraph::Pin::Method>
106 107 108 |
# File 'lib/solargraph/api_map/store.rb', line 106 def method_pins pins_by_class(Solargraph::Pin::Method) end |
#named_macros ⇒ Hash
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/solargraph/api_map/store.rb', line 121 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
91 92 93 |
# File 'lib/solargraph/api_map/store.rb', line 91 def namespace_exists?(fqns) fqns_pins(fqns).any? end |
#namespace_pins ⇒ Array<Solargraph::Pin::Base>
101 102 103 |
# File 'lib/solargraph/api_map/store.rb', line 101 def namespace_pins pins_by_class(Solargraph::Pin::Namespace) end |
#namespaces ⇒ Set<String>
96 97 98 |
# File 'lib/solargraph/api_map/store.rb', line 96 def namespaces @namespaces ||= Set.new end |
#pins_by_class(klass) ⇒ Array<Solargraph::Pin::Base>
146 147 148 |
# File 'lib/solargraph/api_map/store.rb', line 146 def pins_by_class klass @pin_select_cache[klass] ||= @pin_class_hash.select { |key, _| key <= klass }.values.flatten end |