Module: Solargraph::ApiMap::SourceToYard

Included in:
Solargraph::ApiMap
Defined in:
lib/solargraph/api_map/source_to_yard.rb

Instance Method Summary collapse

Instance Method Details

#code_object_at(path) ⇒ YARD::CodeObjects::Base

Get the YARD CodeObject at the specified path.


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

def code_object_at path
  code_object_map[path]
end

#code_object_pathsArray<String>


14
15
16
# File 'lib/solargraph/api_map/source_to_yard.rb', line 14

def code_object_paths
  code_object_map.keys
end

#rake_yard(store) ⇒ void


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/solargraph/api_map/source_to_yard.rb', line 20

def rake_yard store
  code_object_map.clear
  store.namespace_pins.each do |pin|
    next if pin.path.nil? or pin.path.empty?
    if pin.code_object
      code_object_map[pin.path] ||= pin.code_object
      next
    end
    if pin.type == :class
      code_object_map[pin.path] ||= YARD::CodeObjects::ClassObject.new(root_code_object, pin.path)
    else
      code_object_map[pin.path] ||= YARD::CodeObjects::ModuleObject.new(root_code_object, pin.path)
    end
    code_object_map[pin.path].docstring = pin.docstring
    code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil? || code_object_map[pin.path].files.include?(pin.location.filename)
    store.get_includes(pin.path).each do |ref|
      code_object_map[pin.path].instance_mixins.push code_object_map[ref] unless code_object_map[ref].nil? or code_object_map[pin.path].nil?
    end
    store.get_extends(pin.path).each do |ref|
      code_object_map[pin.path].instance_mixins.push code_object_map[ref] unless code_object_map[ref].nil? or code_object_map[pin.path].nil?
      code_object_map[pin.path].class_mixins.push code_object_map[ref] unless code_object_map[ref].nil? or code_object_map[pin.path].nil?
    end
  end
  store.method_pins.each do |pin|
    if pin.code_object
      code_object_map[pin.path] ||= pin.code_object
      next
    end
    code_object_map[pin.path] ||= YARD::CodeObjects::MethodObject.new(code_object_at(pin.namespace), pin.name, pin.scope)
    code_object_map[pin.path].docstring = pin.docstring
    code_object_map[pin.path].visibility = pin.visibility || :public
    code_object_map[pin.path].files.push pin.location.filename unless pin.location.nil? || code_object_map[pin.path].files.include?(pin.location.filename)
    code_object_map[pin.path].parameters = pin.parameters.map do |p|
      n = p.match(/^[a-z0-9_]*:?/i)[0]
      v = nil
      if p.length > n.length
        v = p[n.length..-1].gsub(/^ = /, '')
      end
      [n, v]
    end
  end
end