Class: Solargraph::ApiMap::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/api_map/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pins = []) ⇒ Store


10
11
12
13
# File 'lib/solargraph/api_map/store.rb', line 10

def initialize pins = []
  @pins = pins
  index
end

Instance Attribute Details

#pinsArray<Solargraph::Pin::Base> (readonly)


7
8
9
# File 'lib/solargraph/api_map/store.rb', line 7

def pins
  @pins
end

Instance Method Details

#block_pinsArray<Pin::Block>


129
130
131
# File 'lib/solargraph/api_map/store.rb', line 129

def block_pins
  @block_pins ||= []
end

#domains(fqns) ⇒ Array<String>


106
107
108
109
110
111
112
# File 'lib/solargraph/api_map/store.rb', line 106

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>


72
73
74
# File 'lib/solargraph/api_map/store.rb', line 72

def get_class_variables(fqns)
  namespace_children(fqns).select{|pin| pin.kind == Pin::CLASS_VARIABLE}
end

#get_constants(fqns, visibility = [:public]) ⇒ Array<Solargraph::Pin::Base>


18
19
20
21
22
# File 'lib/solargraph/api_map/store.rb', line 18

def get_constants fqns, visibility = [:public]
  namespace_children(fqns).select { |pin|
    !pin.name.empty? and (pin.kind == Pin::NAMESPACE or pin.kind == Pin::CONSTANT) and visibility.include?(pin.visibility)
  }
end

#get_extends(fqns) ⇒ Array<String>


50
51
52
# File 'lib/solargraph/api_map/store.rb', line 50

def get_extends fqns
  extend_references[fqns] || []
end

#get_includes(fqns) ⇒ Array<String>


44
45
46
# File 'lib/solargraph/api_map/store.rb', line 44

def get_includes fqns
  include_references[fqns] || []
end

#get_instance_variables(fqns, scope = :instance) ⇒ Array<Solargraph::Pin::Base>


63
64
65
66
67
68
# File 'lib/solargraph/api_map/store.rb', line 63

def get_instance_variables(fqns, scope = :instance)
  # namespace_children(fqns).select{|pin| pin.kind == Pin::INSTANCE_VARIABLE and pin.context.scope == scope}
  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>


28
29
30
31
32
33
# File 'lib/solargraph/api_map/store.rb', line 28

def get_methods fqns, scope: :instance, visibility: [:public]
  kinds = [Pin::METHOD, Pin::ATTRIBUTE, Pin::METHOD_ALIAS]
  namespace_children(fqns).select do |pin|
    kinds.include?(pin.kind) && pin.scope == scope && visibility.include?(pin.visibility)
  end
end

#get_path_pins(path) ⇒ Array<Solargraph::Pin::Base>


56
57
58
# File 'lib/solargraph/api_map/store.rb', line 56

def get_path_pins path
  path_pin_hash[path] || []
end

#get_superclass(fqns) ⇒ String


37
38
39
40
# File 'lib/solargraph/api_map/store.rb', line 37

def get_superclass fqns
  return superclass_references[fqns].first if superclass_references.key?(fqns)
  nil
end

#get_symbolsArray<Solargraph::Pin::Base>


77
78
79
# File 'lib/solargraph/api_map/store.rb', line 77

def get_symbols
  symbols.uniq(&:name)
end

#inspectObject


133
134
135
136
# File 'lib/solargraph/api_map/store.rb', line 133

def inspect
  # Avoid insane dumps in specs
  to_s
end

#method_pinsArray<Solargraph::Pin::Base>


99
100
101
102
# File 'lib/solargraph/api_map/store.rb', line 99

def method_pins
  # @method_pins ||= pins.select{|p| p.kind == Pin::METHOD or p.kind == Pin::ATTRIBUTE}
  @method_pins ||= []
end

#named_macrosHash


115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/solargraph/api_map/store.rb', line 115

def named_macros
  @named_macros ||= begin
    result = {}
    pins.each do |pin|
      pin.macros.select{|m| m.tag.tag_name == 'macro'}.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


83
84
85
# File 'lib/solargraph/api_map/store.rb', line 83

def namespace_exists?(fqns)
  fqns_pins(fqns).any?
end

#namespace_pinsArray<Solargraph::Pin::Base>


93
94
95
96
# File 'lib/solargraph/api_map/store.rb', line 93

def namespace_pins
  # @namespace_pins ||= pins.select{|p| p.kind == Pin::NAMESPACE}
  @namespace_pins ||= []
end

#namespacesSet<String>


88
89
90
# File 'lib/solargraph/api_map/store.rb', line 88

def namespaces
  @namespaces ||= Set.new
end