Sha256: 30c8beb84389d9fc578932b5a3a359ef9c8a7dc5a6f7369781be5508da6788af

Contents?: true

Size: 1.2 KB

Versions: 23

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true
# 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
  include YARD::Handlers::Ruby::DecoratorHandlerMethods

  handles method_call(:module_function)
  namespace_only

  process do
    return if 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 :def
          process_decorator do |instance_method|
            make_module_function(instance_method, namespace)
          end
          break
        when :symbol; name = node.first.source
        when :string_content; name = node.source
        else next
        end

        instance_method = MethodObject.new(namespace, name)
        make_module_function(instance_method, namespace)
      end
    end
  end

  def make_module_function(instance_method, namespace)
    class_method = MethodObject.new(namespace, instance_method.name, :module)
    instance_method.copy_to(class_method)
    class_method.visibility = :public
  end
end

Version data entries

23 entries across 23 versions & 5 rubygems

Version Path
kinetic_sdk-5.0.29 gems/yard-0.9.36/lib/yard/handlers/ruby/module_function_handler.rb
kinetic_sdk-5.0.28 gems/yard-0.9.36/lib/yard/handlers/ruby/module_function_handler.rb
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/handlers/ruby/module_function_handler.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/handlers/ruby/module_function_handler.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.37 lib/yard/handlers/ruby/module_function_handler.rb
kinetic_sdk-5.0.27 gems/yard-0.9.36/lib/yard/handlers/ruby/module_function_handler.rb
kinetic_sdk-5.0.26 gems/yard-0.9.36/lib/yard/handlers/ruby/module_function_handler.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.36 lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.35 lib/yard/handlers/ruby/module_function_handler.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/handlers/ruby/module_function_handler.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/yard-0.9.34/lib/yard/handlers/ruby/module_function_handler.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.34 lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.33 lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.32 lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.31 lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.30 lib/yard/handlers/ruby/module_function_handler.rb
yard-0.9.29 lib/yard/handlers/ruby/module_function_handler.rb