Module: Yarr::Command

Defined in:
lib/yarr/command.rb,
lib/yarr/command/concern/responder.rb,
lib/yarr/command/ri.rb,
lib/yarr/command/base.rb,
lib/yarr/command/fake.rb,
lib/yarr/command/list.rb,
lib/yarr/command/evaluate.rb,
lib/yarr/command/url_evaluate.rb,
lib/yarr/command/concern/ast_digger.rb

Overview

Handles the specific commands after dispatch

Defined Under Namespace

Modules: Concern Classes: Base, Evaluate, Fake, List, ListCall, ListClassMethod, ListClassName, ListInstanceMethod, ListMethodName, Ri, RiCall, RiClassMethod, RiClassName, RiInstanceMethod, RiMethodName, URLEvaluate

Constant Summary collapse

COMMANDS =

Commands for_ast can dispatch to.

[RiInstanceMethod,
RiClassMethod,
RiMethodName,
RiClassName,
ListInstanceMethod,
ListClassMethod,
ListMethodName,
ListClassName,
Fake,
Evaluate,
URLEvaluate].freeze

Class Method Summary collapse

Class Method Details

.for_ast(ast) ⇒ Yarr::Command

Selects the appropriate handler for the AST

When no appropriate handler found it returns a Base command.

Examples:

ast = AST.new(command: 'ri', method_name: 'method')
Command.for_ast(ast).class # => Yarr::Command::RiMethodName

Parameters:

  • ast (Yarr::AST)

    the parsed AST structure

Returns:

  • (Yarr::Command)

    the command handler for the incoming command / AST


32
33
34
35
36
# File 'lib/yarr/command.rb', line 32

def self.for_ast(ast)
  COMMANDS
    .find(-> { Base }) { |handler| handler.match?(ast) }
    .new(ast)
end