Module: Server::DefaultHandler
- Included in:
- Demo, InstanceMethods
- Defined in:
- lib/server/default_handler.rb
Overview
The DefaultHandler module
Instance Method Summary collapse
- #channel_active(ctx) ⇒ Object
-
#exception_caught(_ctx, cause) ⇒ Object
rubocop: enable Metrics/AbcSize.
-
#message_received(ctx, msg) ⇒ Object
rubocop: disable Metrics/AbcSize.
Instance Method Details
#channel_active(ctx) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/server/default_handler.rb', line 17 def channel_active(ctx) ::Server.log.info "Channel active: #{ctx.channel}" response = 'Hello, world!' log.trace "Sending response: #{response.inspect}" ctx.channel.writeAndFlush("#{response}\n") end |
#exception_caught(_ctx, cause) ⇒ Object
rubocop: enable Metrics/AbcSize
37 38 39 40 41 |
# File 'lib/server/default_handler.rb', line 37 def exception_caught(_ctx, cause) ::Server.log.error "Exception caught: #{cause}" cause.backtrace.each { |t| ::Server.log.error t } ctx.close() end |
#message_received(ctx, msg) ⇒ Object
rubocop: disable Metrics/AbcSize
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/server/default_handler.rb', line 25 def (ctx, msg) return if msg.nil? msg.chomp! if msg.respond_to?(:chomp!) return if msg.respond_to?(:empty?) && msg.empty? log.trace "##{__method__} channel: #{ctx.channel}, message: #{msg.inspect}" return ctx.close() if @options[:quit_commands].include?(msg.downcase.to_sym) response = msg.upcase log.debug "Sending response: #{response.inspect}" ctx.writeAndFlush("#{response}\n") end |