Class: Solargraph::ApiMap::Store

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(*pinsets) ⇒ Store

Returns a new instance of Store.

Parameters:



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

def initialize *pinsets
  catalog pinsets
end

Instance Method Details

#block_pinsEnumerable<Pin::Block>

Returns:



171
172
173
# File 'lib/solargraph/api_map/store.rb', line 171

def block_pins
  pins_by_class(Pin::Block)
end

#domains(fqns) ⇒ Array<String>

Parameters:

  • fqns (String)

Returns:

  • (Array<String>)


148
149
150
151
152
153
154
# File 'lib/solargraph/api_map/store.rb', line 148

def domains(fqns)
  result = []
  fqns_pins(fqns).each do |nspin|
    result.concat nspin.domains
  end
  result
end

#fqns_pins(fqns) ⇒ Array<Solargraph::Pin::Namespace>

Parameters:

  • fqns (String)

Returns:



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/solargraph/api_map/store.rb', line 184

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>

Parameters:

  • fqns (String)

Returns:



116
117
118
# File 'lib/solargraph/api_map/store.rb', line 116

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>

Parameters:

  • fqns (String)
  • visibility (Array<Symbol>) (defaults to: [:public])

Returns:



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>

Parameters:

  • fqns (String)

Returns:

  • (Array<String>)


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

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

#get_includes(fqns) ⇒ Array<String>

Parameters:

  • fqns (String)

Returns:

  • (Array<String>)


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

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

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

Parameters:

  • fqns (String)
  • scope (Symbol) (defaults to: :instance)

    :class or :instance

Returns:



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

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>

Parameters:

  • fqns (String)
  • scope (Symbol) (defaults to: :instance)
  • visibility (Array<Symbol>) (defaults to: [:public])

Returns:



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

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>

Parameters:

  • path (String)

Returns:



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

def get_path_pins path
  index.path_pin_hash[path]
end

#get_prepends(fqns) ⇒ Array<String>

Parameters:

  • fqns (String)

Returns:

  • (Array<String>)


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

def get_prepends fqns
  prepend_references[fqns] || []
end

#get_superclass(fqns) ⇒ String?

Parameters:

  • fqns (String)

Returns:

  • (String, nil)


71
72
73
74
75
76
77
78
79
# File 'lib/solargraph/api_map/store.rb', line 71

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'
  simplified_literal_name = ComplexType.parse("#{fqns}").simplify_literals.name
  return simplified_literal_name if simplified_literal_name != fqns
  nil
end

#get_symbolsEnumerable<Solargraph::Pin::Base>

Returns:



121
122
123
# File 'lib/solargraph/api_map/store.rb', line 121

def get_symbols
  symbols.uniq(&:name)
end

#inspectObject



46
47
48
# File 'lib/solargraph/api_map/store.rb', line 46

def inspect
  to_s
end

#method_pinsEnumerable<Solargraph::Pin::Method>

Returns:



142
143
144
# File 'lib/solargraph/api_map/store.rb', line 142

def method_pins
  pins_by_class(Solargraph::Pin::Method)
end

#named_macrosHash{String => YARD::Tags::MacroDirective}

Returns:

  • (Hash{String => YARD::Tags::MacroDirective})


157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/solargraph/api_map/store.rb', line 157

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

Parameters:

  • fqns (String)

Returns:

  • (Boolean)


127
128
129
# File 'lib/solargraph/api_map/store.rb', line 127

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

#namespace_pinsEnumerable<Solargraph::Pin::Namespace>

Returns:



137
138
139
# File 'lib/solargraph/api_map/store.rb', line 137

def namespace_pins
  pins_by_class(Solargraph::Pin::Namespace)
end

#namespacesSet<String>

Returns:

  • (Set<String>)


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

def namespaces
  index.namespaces
end

#pinsArray<Solargraph::Pin::Base>

Returns:



15
16
17
# File 'lib/solargraph/api_map/store.rb', line 15

def pins
  index.pins
end

#pins_by_class(klass) ⇒ Set<generic<T>>

Parameters:

  • klass (Class<generic<T>>)

Returns:

  • (Set<generic<T>>)


178
179
180
# File 'lib/solargraph/api_map/store.rb', line 178

def pins_by_class klass
  index.pins_by_class klass
end

#to_sObject



42
43
44
# File 'lib/solargraph/api_map/store.rb', line 42

def to_s
  self.class.to_s
end

#update(*pinsets) ⇒ Boolean

Returns True if the index was updated.

Parameters:

Returns:

  • (Boolean)

    True if the index was updated



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