Module: Yarr::Command

Defined in:
lib/yarr/command.rb,
lib/yarr/command/concern/responder.rb,
lib/yarr/command/ri.rb,
lib/yarr/command/ops.rb,
lib/yarr/command/base.rb,
lib/yarr/command/fact.rb,
lib/yarr/command/fake.rb,
lib/yarr/command/list.rb,
lib/yarr/command/renick.rb,
lib/yarr/command/evaluate.rb,
lib/yarr/command/concern/user.rb,
lib/yarr/command/url_evaluate.rb,
lib/yarr/command/concern/authorize.rb,
lib/yarr/command/concern/ast_digger.rb

Overview

Handles the specific commands after dispatch

Defined Under Namespace

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

Constant Summary collapse

COMMANDS =

Commands for_ast can dispatch to.

ObjectSpace.each_object(Class).select do |subclass|
  subclass.ancestors.include? Base
end

Class Method Summary collapse

Class Method Details

.for_ast(ast, irc = NoIRC) ⇒ 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

  • irc (Cinch::Bot|Yarr::NoIRC) (defaults to: NoIRC)

    irc provider

Returns:

  • (Yarr::Command)

    the command handler for the incoming command / AST


21
22
23
24
25
# File 'lib/yarr/command.rb', line 21

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