Module: Solargraph::YardMap::Mapper::ToMethod

Extended by:
Logging, Helpers
Defined in:
lib/solargraph/yard_map/mapper/to_method.rb

Constant Summary collapse

VISIBILITY_OVERRIDE =
{
  # YARD pays attention to 'private' statements prior to class methods but shouldn't

  ["Rails::Engine", :class, "find_root_with_flag"] => :public
}

Constants included from Logging

Logging::DEFAULT_LOG_LEVEL, Logging::LOG_LEVELS

Class Method Summary collapse

Methods included from Logging

logger

Methods included from Helpers

create_closure_namespace_for, object_location

Class Method Details

.make(code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil) ⇒ Solargraph::Pin::Method



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
62
63
64
65
66
67
68
69
70
71
# File 'lib/solargraph/yard_map/mapper/to_method.rb', line 21

def self.make code_object, name = nil, scope = nil, visibility = nil, closure = nil, spec = nil
  closure ||= create_closure_namespace_for(code_object, spec)
  location = object_location(code_object, spec)
  name ||= code_object.name.to_s
  return_type = ComplexType::SELF if name == 'new'
  comments = code_object.docstring ? code_object.docstring.all.to_s : ''
  final_scope = scope || code_object.scope
  override_key = [closure.path, final_scope, name]
  final_visibility = VISIBILITY_OVERRIDE[override_key]
  final_visibility ||= VISIBILITY_OVERRIDE[[closure.path, final_scope]]
  final_visibility ||= :private if closure.path == 'Kernel' && Kernel.private_instance_methods(false).include?(name.to_sym)
  final_visibility ||= visibility
  final_visibility ||= :private if code_object.module_function? && final_scope == :instance
  final_visibility ||= :public if code_object.module_function? && final_scope == :class
  final_visibility ||= code_object.visibility
  if code_object.is_alias?
    origin_code_object = code_object.namespace.aliases[code_object]
    pin = Pin::MethodAlias.new(
      name: name,
      location: location,
      original: origin_code_object.name.to_s,
      closure: closure,
      comments: comments,
      scope: final_scope,
      visibility: final_visibility,
      explicit: code_object.is_explicit?,
      return_type: return_type,
      parameters: [],
      source: :yardoc,
    )
  else
    pin = Pin::Method.new(
      location: location,
      closure: closure,
      name: name,
      comments: comments,
      scope: final_scope,
      visibility: final_visibility,
      # @todo Might need to convert overloads to signatures

      explicit: code_object.is_explicit?,
      return_type: return_type,
      attribute: code_object.is_attribute?,
      parameters: [],
      source: :yardoc,
    )
    pin.parameters.concat get_parameters(code_object, location, comments, pin)
    pin.parameters.freeze
  end
  logger.debug { "ToMethod.make: Just created method pin: #{pin.inspect}" }
  pin
end