2010-01-16 18:37:14 -08:00
|
|
|
class CallbacksHandler < YARD::Handlers::Ruby::Legacy::Base
|
2011-06-27 23:44:49 -07:00
|
|
|
handles(/\Adefine_callback(\s|\()/)
|
2010-01-16 18:37:14 -08:00
|
|
|
|
|
|
|
def process
|
|
|
|
callback_name = tokval(statement.tokens[2])
|
|
|
|
attr_index = statement.comments.each_with_index {|c, i| break i if c[0] == ?@}
|
|
|
|
if attr_index.is_a?(Fixnum)
|
|
|
|
docstring = statement.comments[0...attr_index]
|
|
|
|
attrs = statement.comments[attr_index..-1]
|
|
|
|
else
|
|
|
|
docstring = statement.comments
|
|
|
|
attrs = []
|
|
|
|
end
|
|
|
|
|
|
|
|
yieldparams = ""
|
|
|
|
attrs.reject! do |a|
|
|
|
|
next unless a =~ /^@yield *(\[.*?\])/
|
|
|
|
yieldparams = $1
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
o = register(MethodObject.new(namespace, "on_#{callback_name}", scope))
|
|
|
|
o.docstring = docstring + [
|
|
|
|
"@return [void]",
|
|
|
|
"@yield #{yieldparams} When the callback is run"
|
|
|
|
] + attrs
|
|
|
|
o.signature = true
|
|
|
|
end
|
|
|
|
end
|