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

Returns a new instance of Store.

Parameters:



12
13
14
15
# File 'lib/solargraph/api_map/store.rb', line 12

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

Instance Attribute Details

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



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

def pins
  @pins
end

Instance Method Details

#block_pinsArray<Pin::Block>

Returns:



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

def block_pins
  pins_by_class(Pin::Block)
end

#domains(fqns) ⇒ Array<String>

Parameters:

  • fqns (String)

Returns:



112
113
114
115
116
117
118
# 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) ⇒ Array<Solargraph::Pin::Base>

Parameters:

  • fqns (String)

Returns:



80
81
82
# 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]) ⇒ Array<Solargraph::Pin::Base>

Parameters:

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

Returns:



20
21
22
23
24
# 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) ⇒ Array<String>

Parameters:

  • fqns (String)

Returns:



59
60
61
# File 'lib/solargraph/api_map/store.rb', line 59

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

#get_includes(fqns) ⇒ Array<String>

Parameters:

  • fqns (String)

Returns:



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

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

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

Parameters:

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

    :class or :instance

Returns:



72
73
74
75
76
# 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]) ⇒ Array<Solargraph::Pin::Base>

Parameters:

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

Returns:



30
31
32
33
34
# 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) ⇒ Array<Solargraph::Pin::Base>

Parameters:

  • path (String)

Returns:



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

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

#get_prepends(fqns) ⇒ Array<String>

Parameters:

  • fqns (String)

Returns:



53
54
55
# File 'lib/solargraph/api_map/store.rb', line 53

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

#get_superclass(fqns) ⇒ String?

Parameters:

  • fqns (String)

Returns:

  • (String, nil)


38
39
40
41
42
43
# 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_symbolsArray<Solargraph::Pin::Base>



85
86
87
# File 'lib/solargraph/api_map/store.rb', line 85

def get_symbols
  symbols.uniq(&:name)
end

#inspectObject



139
140
141
142
# File 'lib/solargraph/api_map/store.rb', line 139

def inspect
  # Avoid insane dumps in specs
  to_s
end

#method_pinsArray<Solargraph::Pin::Method>



106
107
108
# File 'lib/solargraph/api_map/store.rb', line 106

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

#named_macrosHash

Returns:



121
122
123
124
125
126
127
128
129
130
131
132
# 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) ⇒ Boolean

Parameters:

  • fqns (String)

Returns:

  • (Boolean)


91
92
93
# File 'lib/solargraph/api_map/store.rb', line 91

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

#namespace_pinsArray<Solargraph::Pin::Base>



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

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

#namespacesSet<String>

Returns:

  • (Set<String>)


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

def namespaces
  @namespaces ||= Set.new
end

#pins_by_class(klass) ⇒ Array<Solargraph::Pin::Base>

Parameters:

  • klass (Class)

Returns:



146
147
148
# File 'lib/solargraph/api_map/store.rb', line 146

def pins_by_class klass
  @pin_select_cache[klass] ||= @pin_class_hash.select { |key, _| key <= klass }.values.flatten
end