From 74d764b120fad7fd21781b3c2df4abfac5518e78 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 7 Jul 2015 21:39:16 +0200 Subject: Allow actions not to accept the data argument --- lib/action_cable/channel/base.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/action_cable/channel/base.rb') diff --git a/lib/action_cable/channel/base.rb b/lib/action_cable/channel/base.rb index f5d7011a72..fb29ba1893 100644 --- a/lib/action_cable/channel/base.rb +++ b/lib/action_cable/channel/base.rb @@ -52,8 +52,7 @@ module ActionCable action = extract_action(data) if processable_action?(action) - logger.info action_signature(action, data) - public_send action, data + dispatch_action(action, data) else logger.error "Unable to process #{action_signature(action, data)}" end @@ -102,6 +101,16 @@ module ActionCable self.class.instance_methods(false).include?(action) end + def dispatch_action(action, data) + logger.info action_signature(action, data) + + if method(action).arity == 1 + public_send action, data + else + public_send action + end + end + def action_signature(action, data) "#{self.class.name}##{action}".tap do |signature| if (arguments = data.except('action')).any? -- cgit v1.2.3