File: callbacks.rb

package info (click to toggle)
ruby-sass 3.7.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,396 kB
  • sloc: ruby: 32,443; sh: 26; makefile: 25
file content (29 lines) | stat: -rw-r--r-- 817 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class CallbacksHandler < YARD::Handlers::Ruby::Legacy::Base
  handles /\Adefine_callback(\s|\()/

  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?(Integer)
      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