Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ReadlineLogger
- SLACK_EMOJI = ':ruby:'.freeze
- attr_reader :slack_channel
- def initialize slack_channel
- @slack_channel = slack_channel
- end
- def host_name
- @host_name ||= Socket.gethostname
- end
- def readline(prompt)
- Readline.readline(prompt).tap do |user_input|
- next unless user_input && user_input.length > 1
- unless ENV['SYNC_SLACK']
- # We use a new thread to not slow down the prompt
- Thread.new { notify(user_input) }
- else
- # We execute in the same thread for debugging
- notify(user_input)
- end
- end
- end
- def notify(user_input)
- SlackNotifier.new.send_slack_message(user_input, slack_channel, host_name, SLACK_EMOJI)
- end
- # Delegation to not break completion
- def completion_proc
- Readline.completion_proc
- end
- def completion_proc= proc
- Readline.completion_proc = proc
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement