Sha256: e47f2e6fd21242fa26c58eb13a33f14f8f56f968c562ccce90cddfa05f788e1e

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 Bytes

Contents

# Handles module_function calls to turn methods into public class methods.
# Also creates a private instance copy of the method.
class YARD::Handlers::Ruby::ModuleFunctionHandler < YARD::Handlers::Ruby::Base
  handles method_call(:module_function)
  namespace_only

  process do
    return if (ident = statement.jump(:ident)) == statement
    case statement.type
    when :var_ref, :vcall
      self.scope = :module
    when :fcall, :command
      statement[1].traverse do |node|
        case node.type
        when :symbol; name = node.first.source
        when :string_content; name = node.source
        else next
        end
        instance_method = MethodObject.new(namespace, name)
        class_method = MethodObject.new(namespace, name, :module)
        instance_method.copy_to(class_method)
        class_method.visibility = :public
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
deg-yard-0.8.7.4 lib/yard/handlers/ruby/module_function_handler.rb
deg-yard-0.8.7.3 lib/yard/handlers/ruby/module_function_handler.rb
deg-yard-0.8.7.1 lib/yard/handlers/ruby/module_function_handler.rb