Class: Lita::Adapters::Shell

Inherits:
Lita::Adapter show all
Defined in:
lib/lita/adapters/shell.rb

Overview

An adapter that runs Lita in a UNIX shell.

Instance Attribute Summary

Attributes inherited from Lita::Adapter

#robot

Attributes included from Configurable

#configuration_builder

Instance Method Summary collapse

Methods inherited from Lita::Adapter

#config, #initialize, #join, #log, #mention_format, #part, require_config, #set_topic, t, translate, #translate

Methods included from Configurable

#config, #inherited

Methods included from Namespace

#namespace

Constructor Details

This class inherits a constructor from Lita::Adapter

Instance Method Details

#runvoid

This method returns an undefined value.

Creates a “Shell User” and then loops a prompt and input, passing the incoming messages to the robot.


11
12
13
14
15
16
17
18
# File 'lib/lita/adapters/shell.rb', line 11

def run
  user = User.create(1, name: "Shell User")
  @source = Source.new(user: user)
  puts t("startup_message")
  robot.trigger(:connected)

  run_loop
end

#send_messages(_target, strings) ⇒ void

This method returns an undefined value.

Outputs outgoing messages to the shell.


25
26
27
28
29
30
31
32
# File 'lib/lita/adapters/shell.rb', line 25

def send_messages(_target, strings)
  strings = Array(strings)
  strings.reject! { |string| string.empty? }
  unless RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ || !$stdout.tty?
    strings.map! { |string| "\e[32m#{string}\e[0m" }
  end
  puts strings
end

#shut_downvoid

This method returns an undefined value.

Adds a blank line for a nice looking exit.


36
37
38
# File 'lib/lita/adapters/shell.rb', line 36

def shut_down
  puts
end