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 11
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 134
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 111
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 79
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 19
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 58
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 46
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 71
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 29
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 64
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 52
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 37
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 84
def get_symbols
  symbols.uniq(&:name)
end
inspect() click to toggle source
# File lib/solargraph/api_map/store.rb, line 138
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 105
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 120
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 90
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 100
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 95
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 145
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 205
def all_instance_variables
  pins_by_class(Pin::InstanceVariable)
end
extend_references() click to toggle source
# File lib/solargraph/api_map/store.rb, line 190
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 153
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 166
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 182
def include_references
  @include_references ||= {}
end
index() click to toggle source

@return [void]

# File lib/solargraph/api_map/store.rb, line 214
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)
      new_pin.docstring.add_tag(tag) if new_pin
    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 196
def namespace_children name
  namespace_map[name] || []
end
namespace_map() click to toggle source

@return [Hash]

# File lib/solargraph/api_map/store.rb, line 201
def namespace_map
  @namespace_map ||= {}
end
path_pin_hash() click to toggle source
# File lib/solargraph/api_map/store.rb, line 209
def path_pin_hash
  @path_pin_hash ||= {}
end
prepend_references() click to toggle source
# File lib/solargraph/api_map/store.rb, line 186
def prepend_references
  @prepend_references ||= {}
end
superclass_references() click to toggle source
# File lib/solargraph/api_map/store.rb, line 178
def superclass_references
  @superclass_references ||= {}
end
symbols() click to toggle source

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

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