Module: YARD::Handlers::C::HandlerMethods

Includes:
CodeObjects, YARD::Handlers::Common::MethodHandler, Parser::C
Included in:
Base
Defined in:
lib/yard/handlers/c/handler_methods.rb

Overview

Since:

  • 0.8.0

Constant Summary

Constants included from CodeObjects

CodeObjects::BUILTIN_ALL, CodeObjects::BUILTIN_CLASSES, CodeObjects::BUILTIN_EXCEPTIONS, CodeObjects::BUILTIN_EXCEPTIONS_HASH, CodeObjects::BUILTIN_MODULES, CodeObjects::CONSTANTMATCH, CodeObjects::CONSTANTSTART, CodeObjects::CSEP, CodeObjects::CSEPQ, CodeObjects::ISEP, CodeObjects::ISEPQ, CodeObjects::METHODMATCH, CodeObjects::METHODNAMEMATCH, CodeObjects::NAMESPACEMATCH, CodeObjects::NSEP, CodeObjects::NSEPQ

Instance Method Summary collapse

Methods included from YARD::Handlers::Common::MethodHandler

#add_predicate_return_tag

Methods included from CodeObjects::NamespaceMapper

#clear_separators, #default_separator, on_invalidate, #register_separator, #separators, #separators_for_type, #separators_match, #types_for_separator, #unregister_separator_by_type

Instance Method Details

#handle_alias(var_name, new_name, old_name) ⇒ Object

Since:

  • 0.8.0



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/yard/handlers/c/handler_methods.rb', line 86

def handle_alias(var_name, new_name, old_name)
  namespace = namespace_for_variable(var_name)
  return if namespace.nil?
  new_meth = new_name.to_sym
  old_meth = old_name.to_sym
  old_obj = namespace.child(:name => old_meth, :scope => :instance)
  new_obj = register MethodObject.new(namespace, new_meth, :instance) do |o|
    register_visibility(o, visibility)
    register_file_info(o, statement.file, statement.line)
  end

  if old_obj
    new_obj.signature = old_obj.signature
    new_obj.source = old_obj.source
    new_obj.docstring = old_obj.docstring
    new_obj.docstring.object = new_obj
  else
    new_obj.signature = "def #{new_meth}" # this is all we know.
  end

  namespace.aliases[new_obj] = old_meth
end

#handle_attribute(var_name, name, read, write) ⇒ Object

Since:

  • 0.8.0



75
76
77
78
79
80
81
82
83
84
# File 'lib/yard/handlers/c/handler_methods.rb', line 75

def handle_attribute(var_name, name, read, write)
  values = {:read => read.to_i, :write => write.to_i}
  {:read => name, :write => "#{name}="}.each do |type, meth_name|
    next unless values[type] > 0
    obj = handle_method(:instance, var_name, meth_name, nil)
    register_file_info(obj, statement.file, statement.line)
    obj.namespace.attributes[:instance][name] ||= SymbolHash[:read => nil, :write => nil]
    obj.namespace.attributes[:instance][name][type] = obj
  end
end

#handle_class(var_name, class_name, parent, in_module = nil) ⇒ Object

Since:

  • 0.8.0



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yard/handlers/c/handler_methods.rb', line 10

def handle_class(var_name, class_name, parent, in_module = nil)
  parent = nil if parent == "0"
  namespace = in_module ? ensure_variable_defined!(in_module) : Registry.root
  if namespace.nil?
    raise Parser::UndocumentableError,
      "class #{class_name}. Cannot find definition for parent namespace."
  end

  register ClassObject.new(namespace, class_name) do |obj|
    if parent
      parent_class = namespace_for_variable(parent)
      if parent_class.is_a?(Proxy)
        obj.superclass = "::#{parent_class.path}"
        obj.superclass.type = :class
      else
        obj.superclass = parent_class
      end
    end
    namespaces[var_name] = obj
    register_file_info(obj, statement.file, statement.line)
  end
end

#handle_constants(type, var_name, const_name, value) ⇒ Object

Since:

  • 0.8.0



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/yard/handlers/c/handler_methods.rb', line 109

def handle_constants(type, var_name, const_name, value)
  return unless type =~ /^const$|^global_const$/
  namespace = type == 'global_const' ?
    :root : namespace_for_variable(var_name)
  register ConstantObject.new(namespace, const_name) do |obj|
    obj.source_type = :c
    obj.value = value
    register_file_info(obj, statement.file, statement.line)
    find_constant_docstring(obj)
  end
end

#handle_method(scope, var_name, name, func_name, _source_file = nil) ⇒ Object

Since:

  • 0.8.0



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
72
73
# File 'lib/yard/handlers/c/handler_methods.rb', line 46

def handle_method(scope, var_name, name, func_name, _source_file = nil)
  visibility = :public
  case scope
  when "singleton_method"; scope = :class
  when "module_function"; scope = :module
  when "private_method"; scope = :instance; visibility = :private
  else; scope = :instance
  end

  namespace = namespace_for_variable(var_name)

  # Is this method being defined on a core Ruby class or module?
  if namespace.is_a?(Proxy)
    if var_name =~ /^rb_c(\w+)/ && YARD::CodeObjects::BUILTIN_CLASSES.include?($1)
      namespace = namespaces[var_name] = YARD::CodeObjects::ClassObject.new(:root, $1)
    elsif var_name =~ /^rb_m(\w+)/ && YARD::CodeObjects::BUILTIN_MODULES.include?($1)
      namespace = namespaces[var_name] = YARD::CodeObjects::ModuleObject.new(:root, $1)
    end
  end

  return if namespace.nil? # XXX: raise UndocumentableError might be too noisy.
  register MethodObject.new(namespace, name, scope) do |obj|
    register_visibility(obj, visibility)
    find_method_body(obj, func_name)
    obj.explicit = true
    add_predicate_return_tag(obj) if name =~ /\?$/
  end
end

#handle_module(var_name, module_name, in_module = nil) ⇒ Object

Since:

  • 0.8.0



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/yard/handlers/c/handler_methods.rb', line 33

def handle_module(var_name, module_name, in_module = nil)
  namespace = in_module ? ensure_variable_defined!(in_module) : Registry.root
  if namespace.nil?
    raise Parser::UndocumentableError,
      "module #{module_name}. Cannot find definition for parent namespace."
  end

  register ModuleObject.new(namespace, module_name) do |obj|
    namespaces[var_name] = obj
    register_file_info(obj, statement.file, statement.line)
  end
end