From 81ae9ee32162ececbd70664b2821e7c636eaed8b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson <david@loudthinking.com> Date: Sun, 21 Jun 2015 21:08:20 +0200 Subject: Consolidate all identification logic in a single concern --- lib/action_cable/connection.rb | 2 +- lib/action_cable/connection/base.rb | 10 ++-------- lib/action_cable/connection/identification.rb | 26 +++++++++++++++++++++++++ lib/action_cable/connection/identifier.rb | 17 ---------------- lib/action_cable/connection/internal_channel.rb | 4 ++++ 5 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 lib/action_cable/connection/identification.rb delete mode 100644 lib/action_cable/connection/identifier.rb (limited to 'lib/action_cable') diff --git a/lib/action_cable/connection.rb b/lib/action_cable/connection.rb index a9048926e4..8a695a3d0d 100644 --- a/lib/action_cable/connection.rb +++ b/lib/action_cable/connection.rb @@ -1,8 +1,8 @@ module ActionCable module Connection autoload :Base, 'action_cable/connection/base' + autoload :Identification, 'action_cable/connection/identification' autoload :InternalChannel, 'action_cable/connection/internal_channel' - autoload :Identifier, 'action_cable/connection/identifier' autoload :TaggedLoggerProxy, 'action_cable/connection/tagged_logger_proxy' end end diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb index 4b73a90dc1..0d666713d2 100644 --- a/lib/action_cable/connection/base.rb +++ b/lib/action_cable/connection/base.rb @@ -1,17 +1,11 @@ module ActionCable module Connection class Base - include InternalChannel, Identifier + include Identification + include InternalChannel PING_INTERVAL = 3 - class_attribute :identifiers - self.identifiers = Set.new - - def self.identified_by(*identifiers) - self.identifiers += identifiers - end - attr_reader :env, :server, :logger delegate :worker_pool, :pubsub, to: :server diff --git a/lib/action_cable/connection/identification.rb b/lib/action_cable/connection/identification.rb new file mode 100644 index 0000000000..246636198b --- /dev/null +++ b/lib/action_cable/connection/identification.rb @@ -0,0 +1,26 @@ +module ActionCable + module Connection + module Identification + extend ActiveSupport::Concern + + included do + class_attribute :identifiers + self.identifiers = Set.new + end + + class_methods do + def identified_by(*identifiers) + self.identifiers += identifiers + end + end + + def connection_identifier + @connection_identifier ||= connection_gid identifiers.map { |id| instance_variable_get("@#{id}") }.compact + end + + def connection_gid(ids) + ids.map { |o| o.to_global_id.to_s }.sort.join(":") + end + end + end +end diff --git a/lib/action_cable/connection/identifier.rb b/lib/action_cable/connection/identifier.rb deleted file mode 100644 index 62524263bd..0000000000 --- a/lib/action_cable/connection/identifier.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ActionCable - module Connection - module Identifier - def internal_redis_channel - "action_cable/#{connection_identifier}" - end - - def connection_identifier - @connection_identifier ||= connection_gid identifiers.map { |id| instance_variable_get("@#{id}") }.compact - end - - def connection_gid(ids) - ids.map { |o| o.to_global_id.to_s }.sort.join(":") - end - end - end -end diff --git a/lib/action_cable/connection/internal_channel.rb b/lib/action_cable/connection/internal_channel.rb index 3a11bcaf7b..55dfc72777 100644 --- a/lib/action_cable/connection/internal_channel.rb +++ b/lib/action_cable/connection/internal_channel.rb @@ -3,6 +3,10 @@ module ActionCable module InternalChannel extend ActiveSupport::Concern + def internal_redis_channel + "action_cable/#{connection_identifier}" + end + def subscribe_to_internal_channel if connection_identifier.present? callback = -> (message) { process_internal_message(message) } -- cgit v1.2.3