From 09974941ccc7f782d163197d1a96440fcc811e85 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 22 Jun 2015 16:01:41 +0200 Subject: Extract helper method --- lib/action_cable/connection/base.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/action_cable/connection') diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index c3c99dcec4..4bc6a14aaa 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -53,7 +53,7 @@ module ActionCable def receive(data_in_json) if websocket_alive? - data = ActiveSupport::JSON.decode data_in_json + data = decode_json data_in_json case data['command'] when 'subscribe' then subscriptions.add data @@ -123,13 +123,17 @@ module ActionCable def process_message(message) - subscriptions.find(message['identifier']).perform_action(ActiveSupport::JSON.decode(message['data'])) + subscriptions.find(message['identifier']).perform_action decode_json(message['data']) rescue Exception => e logger.error "Could not process message (#{message.inspect})" log_exception(e) end + def decode_json(json) + ActiveSupport::JSON.decode json + end + def respond_to_invalid_request [ 404, { 'Content-Type' => 'text/plain' }, [ 'Page not found' ] ] end -- cgit v1.2.3