class Solargraph::ApiMap::Store


core.
Queryable collection of Pins representing a Workspace, gems and the Ruby

def all_instance_variables

Returns:
  • (Enumerable) -
def all_instance_variables
  pins_by_class(Pin::InstanceVariable)
end

def block_pins

Returns:
  • (Enumerable) -
def block_pins
  pins_by_class(Pin::Block)
end

def cacheable_pins

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

def domains(fqns)

Returns:
  • (Array) -

Parameters:
  • fqns (String) --
def domains(fqns)
  result = []
  fqns_pins(fqns).each do |nspin|
    result.concat nspin.domains
  end
  result
end

def extend_references

Returns:
  • (Hash{String => Array}) -
def extend_references
  @extend_references ||= {}
end

def fqns_pins fqns

Returns:
  • (Array) -

Parameters:
  • fqns (String) --
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

def fqns_pins_map

Returns:
  • (Hash{::Array(String, String) => ::Array}) -
def fqns_pins_map
  @fqns_pins_map ||= Hash.new do |h, (base, name)|
    value = namespace_children(base).select { |pin| pin.name == name && pin.is_a?(Pin::Namespace) }
    h[[base, name]] = value
  end
end

def get_class_variables(fqns)

Returns:
  • (Enumerable) -

Parameters:
  • fqns (String) --
def get_class_variables(fqns)
  namespace_children(fqns).select{|pin| pin.is_a?(Pin::ClassVariable)}
end

def get_constants fqns, visibility = [:public]

Returns:
  • (Enumerable) -

Parameters:
  • visibility (Array) --
  • fqns (String) --
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

def get_extends fqns

Returns:
  • (Array) -

Parameters:
  • fqns (String) --
def get_extends fqns
  extend_references[fqns] || []
end

def get_includes fqns

Returns:
  • (Array) -

Parameters:
  • fqns (String) --
def get_includes fqns
  include_references[fqns] || []
end

def get_instance_variables(fqns, scope = :instance)

Returns:
  • (Enumerable) -

Parameters:
  • scope (Symbol) -- :class or :instance
  • fqns (String) --
def get_instance_variables(fqns, scope = :instance)
  all_instance_variables.select { |pin|
    pin.binder.namespace == fqns && pin.binder.scope == scope
  }
end

def get_methods fqns, scope: :instance, visibility: [:public]

Returns:
  • (Enumerable) -

Parameters:
  • visibility (Array) --
  • scope (Symbol) --
  • fqns (String) --
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

def get_path_pins path

Returns:
  • (Array) -

Parameters:
  • path (String) --
def get_path_pins path
  path_pin_hash[path] || []
end

def get_prepends fqns

Returns:
  • (Array) -

Parameters:
  • fqns (String) --
def get_prepends fqns
  prepend_references[fqns] || []
end

def get_superclass fqns

Returns:
  • (String, nil) -

Parameters:
  • fqns (String) --
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

def get_symbols

Returns:
  • (Enumerable) -
def get_symbols
  symbols.uniq(&:name)
end

def include_references

Returns:
  • (Hash{String => Array}) -
def include_references
  @include_references ||= {}
end

def index

Returns:
  • (void) -
def index
  set = pins.to_set
  @pin_class_hash = set.classify(&:class).transform_values(&:to_a)
  # @type [Hash{Class => ::Array<Solargraph::Pin::Base>}]

  @pin_select_cache = {}
  @namespace_map = set.classify(&:namespace)
  @path_pin_hash = set.classify(&:path)
  @namespaces = @path_pin_hash.keys.compact.to_set
  pins_by_class(Pin::Reference::Include).each do |pin|
    store_parametric_reference(include_references, pin)
  end
  # @todo move the rest of these reference pins over to use

  #   generic types, adding rbs_map/conversions.rb code to

  #   populate type parameters and adding related specs ensuring

  #   the generics get resolved, along with any api_map.rb

  #   changes needed in

  pins_by_class(Pin::Reference::Prepend).each do |pin|
    prepend_references[pin.namespace] ||= []
    prepend_references[pin.namespace].push pin.name
  end
  pins_by_class(Pin::Reference::Extend).each do |pin|
    extend_references[pin.namespace] ||= []
    extend_references[pin.namespace].push pin.name
  end
  pins_by_class(Pin::Reference::Superclass).each do |pin|
    superclass_references[pin.namespace] ||= []
    superclass_references[pin.namespace].push pin.name
  end
  pins_by_class(Pin::Reference::Override).each do |ovr|
    pin = get_path_pins(ovr.name).first
    next if pin.nil?
    new_pin = if pin.path.end_with?('#initialize')
      get_path_pins(pin.path.sub(/#initialize/, '.new')).first
    end
    (ovr.tags.map(&:tag_name) + ovr.delete).uniq.each do |tag|
      pin.docstring.delete_tags tag
      new_pin.docstring.delete_tags tag if new_pin
    end
    ovr.tags.each do |tag|
      pin.docstring.add_tag(tag)
      redefine_return_type pin, tag
      if new_pin
        new_pin.docstring.add_tag(tag)
        redefine_return_type new_pin, tag
      end
    end
  end
end

def initialize pins = []

Parameters:
  • pins (Enumerable) --
def initialize pins = []
  @pins = pins
  index
end

def inspect

def inspect
  # Avoid insane dumps in specs

  to_s
end

def method_pins

Returns:
  • (Enumerable) -
def method_pins
  pins_by_class(Solargraph::Pin::Method)
end

def named_macros

Returns:
  • (Hash{String => YARD::Tags::MacroDirective}) -
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

def namespace_children name

Returns:
  • (Enumerable) -

Parameters:
  • name (String) --
def namespace_children name
  namespace_map[name] || []
end

def namespace_exists?(fqns)

Returns:
  • (Boolean) -

Parameters:
  • fqns (String) --
def namespace_exists?(fqns)
  fqns_pins(fqns).any?
end

def namespace_map

Returns:
  • (Hash{String => Enumerable}) - Hash{String => Enumerable}
def namespace_map
  @namespace_map ||= {}
end

def namespace_pins

Returns:
  • (Enumerable) -
def namespace_pins
  pins_by_class(Solargraph::Pin::Namespace)
end

def namespaces

Returns:
  • (Set) -
def namespaces
  @namespaces ||= Set.new
end

def path_pin_hash

Returns:
  • (Hash{String => Array}) -
def path_pin_hash
  @path_pin_hash ||= {}
end

def pins_by_class klass

Returns:
  • (Set) -

Parameters:
  • klass (Class) --
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

def prepend_references

Returns:
  • (Hash{String => Array}) -
def prepend_references
  @prepend_references ||= {}
end

def redefine_return_type pin, tag

Returns:
  • (void) -

Parameters:
  • tag (String) --
  • pin (Pin::Base) --
def redefine_return_type pin, tag
  return unless pin && tag.tag_name == 'return'
  pin.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
  pin.signatures.each do |sig|
    sig.instance_variable_set(:@return_type, ComplexType.try_parse(tag.type))
  end
end

def store_parametric_reference(h, reference_pin)

Returns:
  • (void) -

Parameters:
  • reference_pin (Pin::Reference) --
  • h (Hash{String => Pin:Base}) --
def store_parametric_reference(h, reference_pin)
  referenced_ns = reference_pin.name
  referenced_tag_params = reference_pin.generic_values
  referenced_tag = referenced_ns +
                   if referenced_tag_params && referenced_tag_params.length > 0
                     "<" + referenced_tag_params.join(', ') + ">"
                   else
                     ''
                   end
  referencing_ns = reference_pin.namespace
  h[referencing_ns] ||= []
  h[referencing_ns].push referenced_tag
end

def superclass_references

Returns:
  • (Hash{String => Array}) -
def superclass_references
  @superclass_references ||= {}
end

def symbols

Returns:
  • (Enumerable) -
def symbols
  pins_by_class(Pin::Symbol)
end