class Ellen::Adapters::Shell

Constants

PROMPT
SOURCE
USAGE

Attributes

stopped[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Ellen::Adapters::Base::new
# File lib/ellen/adapters/shell.rb, line 14
def initialize(*args)
  super
  remember
end

Public Instance Methods

run() click to toggle source
# File lib/ellen/adapters/shell.rb, line 19
def run
  explain
  listen
end
say(message) click to toggle source
# File lib/ellen/adapters/shell.rb, line 24
def say(message)
  Ellen.logger.info(message[:body])
end

Private Instance Methods

explain() click to toggle source
# File lib/ellen/adapters/shell.rb, line 30
def explain
  Ellen.logger.info(USAGE)
end
history_file() click to toggle source
# File lib/ellen/adapters/shell.rb, line 75
def history_file
  @history_file ||= history_pathname.open("a").tap do |file|
    file.sync = true
  end
end
history_pathname() click to toggle source
# File lib/ellen/adapters/shell.rb, line 71
def history_pathname
  @history_pathname ||= Pathname.new("~/.ellen_history").expand_path
end
listen() click to toggle source
# File lib/ellen/adapters/shell.rb, line 40
def listen
  step until stopped?
rescue Interrupt
  stop
end
read() click to toggle source
# File lib/ellen/adapters/shell.rb, line 34
def read
  Readline.readline(PROMPT, true).tap do |line|
    history_file.puts(line)
  end
end
remember() click to toggle source
# File lib/ellen/adapters/shell.rb, line 63
def remember
  if history_pathname.exist?
    history_pathname.each_line do |line|
      Readline::HISTORY << line.rstrip
    end
  end
end
step() click to toggle source
# File lib/ellen/adapters/shell.rb, line 46
def step
  case body = read
  when "exit", "quit"
    stop
  else
    robot.receive(body: body, source: SOURCE)
  end
end
stop() click to toggle source
# File lib/ellen/adapters/shell.rb, line 59
def stop
  self.stopped = true
end
stopped?() click to toggle source
# File lib/ellen/adapters/shell.rb, line 55
def stopped?
  !!stopped
end