class Solargraph::ApiMap::Store

Attributes

pins[R]

@return [Enumerable<Solargraph::Pin::Base>]

Public Class Methods

new(pins = []) click to toggle source

@param pins [Enumerable<Solargraph::Pin::Base>]

# File lib/solargraph/api_map/store.rb, line 12
def initialize pins = []
  @pins = pins
  index
end

Public Instance Methods

block_pins() click to toggle source

@return [Enumerable<Pin::Block>]

# File lib/solargraph/api_map/store.rb, line 135
def block_pins
  pins_by_class(Pin::Block)
end
domains(fqns) click to toggle source

@param fqns [String] @return [Array<String>]

# 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) click to toggle source

@param fqns [String] @return [Enumerable<Solargraph::Pin::Base>]

# 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]) click to toggle source

@param fqns [String] @param visibility [Array<Symbol>] @return [Enumerable<Solargraph::Pin::Base>]

# 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) click to toggle source

@param fqns [String] @return [Array<String>]

# File lib/solargraph/api_map/store.rb, line 59
def get_extends fqns
  extend_references[fqns] || []
end
get_includes(fqns) click to toggle source

@param fqns [String] @return [Array<String>]

# File lib/solargraph/api_map/store.rb, line 47
def get_includes fqns
  include_references[fqns] || []
end
get_instance_variables(fqns, scope = :instance) click to toggle source

@param fqns [String] @param scope [Symbol] :class or :instance @return [Enumerable<Solargraph::Pin::Base>]

# 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]) click to toggle source

@param fqns [String] @param scope [Symbol] @param visibility [Array<Symbol>] @return [Enumerable<Solargraph::Pin::Base>]

# 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) click to toggle source

@param path [String] @return [Enumerable<Solargraph::Pin::Base>]

# File lib/solargraph/api_map/store.rb, line 65
def get_path_pins path
  path_pin_hash[path] || []
end
get_prepends(fqns) click to toggle source

@param fqns [String] @return [Array<String>]

# File lib/solargraph/api_map/store.rb, line 53
def get_prepends fqns
  prepend_references[fqns] || []
end
get_superclass(fqns) click to toggle source

@param fqns [String] @return [String, nil]

# 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() click to toggle source

@return [Enumerable<Solargraph::Pin::Base>]

# File lib/solargraph/api_map/store.rb, line 85
def get_symbols
  symbols.uniq(&:name)
end
inspect() click to toggle source
# File lib/solargraph/api_map/store.rb, line 139
def inspect
  # Avoid insane dumps in specs
  to_s
end
method_pins() click to toggle source

@return [Enumerable<Solargraph::Pin::Method>]

# File lib/solargraph/api_map/store.rb, line 106
def method_pins
  pins_by_class(Solargraph::Pin::Method)
end
named_macros() click to toggle source

@return [Hash]

# 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) click to toggle source

@param fqns [String] @return [Boolean]

# File lib/solargraph/api_map/store.rb, line 91
def namespace_exists?(fqns)
  fqns_pins(fqns).any?
end
namespace_pins() click to toggle source

@return [Enumerable<Solargraph::Pin::Base>]

# File lib/solargraph/api_map/store.rb, line 101
def namespace_pins
  pins_by_class(Solargraph::Pin::Namespace)
end
namespaces() click to toggle source

@return [Set<String>]

# File lib/solargraph/api_map/store.rb, line 96
def namespaces
  @namespaces ||= Set.new
end
pins_by_class(klass) click to toggle source

@param klass [Class] @return [Enumerable<Solargraph::Pin::Base>]

# File lib/solargraph/api_map/store.rb, line 146
def pins_by_class klass
  @pin_select_cache[klass] ||= @pin_class_hash.each_with_object(Set.new) { |(key, o), n| n.merge(o) if key <= klass }
end

Private Instance Methods

all_instance_variables() click to toggle source
# File lib/solargraph/api_map/store.rb, line 206
def all_instance_variables
  pins_by_class(Pin::InstanceVariable)
end
extend_references() click to toggle source
# File lib/solargraph/api_map/store.rb, line 191
def extend_references
  @extend_references ||= {}
end
fqns_pins(fqns) click to toggle source

@param fqns [String] @return [Array<Solargraph::Pin::Namespace>]

# File lib/solargraph/api_map/store.rb, line 154
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
fqns_pins_map() click to toggle source
# File lib/solargraph/api_map/store.rb, line 167
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
include_references() click to toggle source
# File lib/solargraph/api_map/store.rb, line 183
def include_references
  @include_references ||= {}
end
index() click to toggle source

@return [void]

# File lib/solargraph/api_map/store.rb, line 215
def index
  set = pins.to_set
  @pin_class_hash = set.classify(&:class).transform_values(&:to_a)
  @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|
    include_references[pin.namespace] ||= []
    include_references[pin.namespace].push pin.name
  end
  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.to_sym
      new_pin.docstring.delete_tags tag.to_sym 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
namespace_children(name) click to toggle source

@param name [String] @return [Enumerable<Solargraph::Pin::Base>]

# File lib/solargraph/api_map/store.rb, line 197
def namespace_children name
  namespace_map[name] || []
end
namespace_map() click to toggle source

@return [Hash]

# File lib/solargraph/api_map/store.rb, line 202
def namespace_map
  @namespace_map ||= {}
end
path_pin_hash() click to toggle source
# File lib/solargraph/api_map/store.rb, line 210
def path_pin_hash
  @path_pin_hash ||= {}
end
prepend_references() click to toggle source
# File lib/solargraph/api_map/store.rb, line 187
def prepend_references
  @prepend_references ||= {}
end
redefine_return_type(pin, tag) click to toggle source
# File lib/solargraph/api_map/store.rb, line 259
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
superclass_references() click to toggle source
# File lib/solargraph/api_map/store.rb, line 179
def superclass_references
  @superclass_references ||= {}
end
symbols() click to toggle source

@return [Enumerable<Solargraph::Pin::Symbol>]

# File lib/solargraph/api_map/store.rb, line 175
def symbols
  pins_by_class(Pin::Symbol)
end