Sha256: 75cfa62666a47537087e026508d5179b9585232ecbd8c83fa1d8b3807a1fd0b9

Contents?: true

Size: 1.17 KB

Versions: 17

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true
# Handles the 'include' statement to mixin a module in the instance scope
class YARD::Handlers::Ruby::MixinHandler < YARD::Handlers::Ruby::Base
  handles method_call(:include)
  namespace_only

  process do
    errors = []
    statement.parameters(false).reverse.each do |mixin|
      begin
        process_mixin(mixin)
      rescue YARD::Parser::UndocumentableError => err
        errors << err.message
      end
    end
    unless errors.empty?
      msg = errors.size == 1 ? ": #{errors[0]}" : "s: #{errors.join(", ")}"
      raise YARD::Parser::UndocumentableError, "mixin#{msg} for class #{namespace.path}"
    end
  end

  protected

  def process_mixin(mixin)
    raise YARD::Parser::UndocumentableError unless mixin.ref?
    raise YARD::Parser::UndocumentableError if mixin.first.type == :ident

    case obj = Proxy.new(namespace, mixin.source)
    when ConstantObject # If a constant is included, use its value as the real object
      obj = Proxy.new(namespace, obj.value, :module)
    else
      obj = Proxy.new(namespace, mixin.source, :module)
    end

    namespace.mixins(scope).unshift(obj) unless namespace.mixins(scope).include?(obj)
  end
end

Version data entries

17 entries across 16 versions & 4 rubygems

Version Path
yard-0.9.20 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.19 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.16 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.15 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.14 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.13 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.12 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.11 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.10 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.9 lib/yard/handlers/ruby/mixin_handler.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.4.0/gems/yard-0.9.8/lib/yard/handlers/ruby/mixin_handler.rb
etude_for_ruby-0.1.4 vendor/bundle/ruby/2.2.0/gems/yard-0.9.8/lib/yard/handlers/ruby/mixin_handler.rb
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/yard-0.9.8/lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.8 lib/yard/handlers/ruby/mixin_handler.rb
abaci-0.3.0 vendor/bundle/gems/yard-0.9.7/lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.7 lib/yard/handlers/ruby/mixin_handler.rb
yard-0.9.6 lib/yard/handlers/ruby/mixin_handler.rb