class Daneel::Scripts::Reload

Public Instance Methods

help() click to toggle source
# File lib/daneel/scripts/reload.rb, line 21
def help
  reload = {"reload" => "restarts and reloads #{robot.name}'s code"}
  update = {"update" => "updates #{robot.name}'s code from git and restarts"}
  in_git? ? reload.merge(update) : reload
end
receive(room, message, user) click to toggle source
# File lib/daneel/scripts/reload.rb, line 8
def receive(room, message, user)
  case message.command
  when /^update$/
    return unless in_git?
    system("cd #{root} && git pull origin master && bundle install")
    room.say "updated, brb"
    restart
  when /^reload$/
    room.say "k, brb"
    restart
  end
end

Private Instance Methods

in_git?() click to toggle source
# File lib/daneel/scripts/reload.rb, line 45
def in_git?
  @in_git ||= root.join(".git").directory?
end
restart() click to toggle source
# File lib/daneel/scripts/reload.rb, line 29
def restart
  bin = root.join("bin/daneel").realpath.to_s
  cmd = [Gem.ruby, "-S", bin, *ARGV]

  logger.debug "Reloading: #{cmd.join(' ')}"
  exec *cmd
end
root() click to toggle source
# File lib/daneel/scripts/reload.rb, line 37
def root
  @root ||= begin
    root = Pathname.new(__FILE__).join("../../../..").expand_path
    logger.debug "Found root directory #{root}"
    root
  end
end