Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class ReadlineLogger
  2.  
  3. SLACK_EMOJI = ':ruby:'.freeze
  4.  
  5. attr_reader :slack_channel
  6.  
  7. def initialize slack_channel
  8. @slack_channel = slack_channel
  9. end
  10.  
  11. def host_name
  12. @host_name ||= Socket.gethostname
  13. end
  14.  
  15. def readline(prompt)
  16. Readline.readline(prompt).tap do |user_input|
  17. next unless user_input && user_input.length > 1
  18. unless ENV['SYNC_SLACK']
  19. # We use a new thread to not slow down the prompt
  20. Thread.new { notify(user_input) }
  21. else
  22. # We execute in the same thread for debugging
  23. notify(user_input)
  24. end
  25. end
  26. end
  27.  
  28. def notify(user_input)
  29. SlackNotifier.new.send_slack_message(user_input, slack_channel, host_name, SLACK_EMOJI)
  30. end
  31.  
  32. # Delegation to not break completion
  33. def completion_proc
  34. Readline.completion_proc
  35. end
  36.  
  37. def completion_proc= proc
  38. Readline.completion_proc = proc
  39. end
  40.  
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement