Module: YARD::Handlers::Ruby::MacroHandlerMethods
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::CSEP, CodeObjects::CSEPQ, CodeObjects::ISEP, CodeObjects::ISEPQ, CodeObjects::METHODMATCH, CodeObjects::METHODNAMEMATCH, CodeObjects::NAMESPACEMATCH, CodeObjects::NSEP, CodeObjects::NSEPQ
Instance Method Summary
collapse
Instance Method Details
#create_attribute_data(object) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 48
def create_attribute_data(object)
return unless object.docstring.tag(:attribute)
ensure_loaded!(namespace)
clean_name = object.name.to_s.sub(/=$/, '')
namespace.attributes[object.scope][clean_name] ||= SymbolHash[:read => nil, :write => nil]
if attribute_readable?
namespace.attributes[object.scope][clean_name][:read] = object
end
if attribute_writable?
if object.name.to_s[-1,1] == '='
writer = object
else
writer = MethodObject.new(namespace, object.name.to_s + '=', object.scope)
register(writer)
writer.signature = "def #{object.name}=(value)"
writer.visibility = object.visibility
writer.dynamic = true
end
namespace.attributes[object.scope][clean_name][:write] = writer
end
end
|
#expand_macro(object, macro) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 27
def expand_macro(object, macro)
if @docstring
object.docstring = @docstring
object.docstring.tags.each do |tag|
tag.object = object if tag.respond_to?(:object=)
end
else
super(object, macro)
end
end
|
#expanded_macro_or_docstring ⇒ Object
20
21
22
23
24
25
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 20
def expanded_macro_or_docstring
return @docstring unless @macro
all_params = ([caller_method] + call_params).compact
data = MacroObject.apply_macro(@macro, @docstring, all_params, statement.source)
Docstring.new(data)
end
|
#find_or_create_macro(docstring) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 8
def find_or_create_macro(docstring)
return @macro if @macro
return if @macro = super(docstring)
(globals.__attached_macros[caller_method] || []).each do |macro|
namespace.inheritance_tree.each do |obj|
break(@macro = macro) if obj == macro.method_object.namespace
end
end
end
|
#method_name ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 70
def method_name
name = nil
[:method, :attribute, :overload].each do |tag_name|
if tag = @docstring.tag(tag_name)
name = tag.send(tag_name == :attribute ? :text : :name).to_s
if tag_name == :method && name =~ /\(|\s/
overload = Tags::OverloadTag.new(:overload, name)
@docstring.add_tag(overload)
end
break
end
end
name = nil if name =~ /\A\s*\Z/
name ||= call_params.first
return unless name
if name =~ /\A\s*([^\(; \t]+)/
name = $1
end
if @docstring.tag(:attribute) && !attribute_readable?
name = name + '='
end
name
end
|
#method_signature ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 94
def method_signature
if @docstring.tag(:method)
name = @docstring.tag(:method).name
elsif @docstring.tag(:overload)
name = @docstring.tag(:overload).signature
elsif @docstring.tag(:attribute)
name = @docstring.tag(:attribute).text
name += '=(value)' if !attribute_readable?
else
name = method_name
end
name = nil if name =~ /\A\s*\Z/
name ||= call_params.first
name =~ /^def\b/ ? name : "def #{name}"
end
|
#sanitize_scope ⇒ Object
38
39
40
41
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 38
def sanitize_scope
tmp_scope = @docstring.tag(:scope) ? @docstring.tag(:scope).text : ''
%w(class instance).include?(tmp_scope) ? tmp_scope.to_sym : scope
end
|
#sanitize_visibility ⇒ Object
43
44
45
46
|
# File 'lib/yard/handlers/ruby/macro_handler_methods.rb', line 43
def sanitize_visibility
vis = @docstring.tag(:visibility) ? @docstring.tag(:visibility).text : ''
%w(public protected private).include?(vis) ? vis.to_sym : visibility
end
|