1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

ActionCable::StorageAdapter ==> ActionCable::SubscriptionAdapter

This commit is contained in:
Jon Moss 2016-01-15 19:07:18 -05:00
parent 6aeaed4c1a
commit 4c5d5b75ab
11 changed files with 23 additions and 21 deletions

View file

@ -47,5 +47,5 @@ module ActionCable
autoload :Connection
autoload :Channel
autoload :RemoteConnections
autoload :StorageAdapter
autoload :SubscriptionAdapter
end

View file

@ -47,7 +47,7 @@ module ActionCable
# Adapter used for all streams/broadcasting.
def adapter
@adapter ||= config.storage_adapter.new(self)
@adapter ||= config.subscription_adapter.new(self)
end
# All the identifiers applied to the connection class associated with this server.

View file

@ -30,12 +30,14 @@ module ActionCable
end
end
# Returns constant of storage adapter specified in config/cable.yml
# Returns constant of subscription adapter specified in config/cable.yml
# If the adapter cannot be found, this will default to the Redis adapter
def storage_adapter
def subscription_adapter
# Defaults to redis if no adapter is set
adapter = cable.fetch('adapter') { 'redis' }
"ActionCable::StorageAdapter::#{adapter.camelize}".constantize
adapter.camelize
adapter = 'PostgreSQL' if adapter == 'Postgresql'
"ActionCable::SubscriptionAdapter::#{adapter}".constantize
end
end
end

View file

@ -1,7 +0,0 @@
module ActionCable
module StorageAdapter
autoload :Base, 'action_cable/storage_adapter/base'
autoload :PostgreSQL, 'action_cable/storage_adapter/postgresql'
autoload :Redis, 'action_cable/storage_adapter/redis'
end
end

View file

@ -0,0 +1,7 @@
module ActionCable
module SubscriptionAdapter
autoload :Base, 'action_cable/subscription_adapter/base'
autoload :PostgreSQL, 'action_cable/subscription_adapter/postgresql'
autoload :Redis, 'action_cable/subscription_adapter/redis'
end
end

View file

@ -1,5 +1,5 @@
module ActionCable
module StorageAdapter
module SubscriptionAdapter
class Base
attr_reader :logger, :server

View file

@ -7,7 +7,7 @@ rescue Gem::LoadError => e
end
module ActionCable
module StorageAdapter
module SubscriptionAdapter
class PostgreSQL < Base
# The storage instance used for broadcasting. Not intended for direct user use.
def broadcast(channel, payload)

View file

@ -6,7 +6,7 @@ rescue Gem::LoadError => e
end
module ActionCable
module StorageAdapter
module SubscriptionAdapter
class Redis < Base
def broadcast(channel, payload)
redis_conn.publish(channel, payload)

View file

@ -1,4 +1,4 @@
class SuccessAdapter < ActionCable::StorageAdapter::Base
class SuccessAdapter < ActionCable::SubscriptionAdapter::Base
def broadcast(channel, payload)
end

View file

@ -7,11 +7,11 @@ class TestServer
def initialize
@logger = ActiveSupport::TaggedLogging.new ActiveSupport::Logger.new(StringIO.new)
@config = OpenStruct.new(log_tags: [], storage_adapter: SuccessAdapter)
@config = OpenStruct.new(log_tags: [], subscription_adapter: SuccessAdapter)
end
def adapter
@config.storage_adapter.new(self)
@config.subscription_adapter.new(self)
end
def send_async

View file

@ -1,15 +1,15 @@
require 'test_helper'
require 'stubs/test_server'
class ActionCable::StorageAdapter::BaseTest < ActionCable::TestCase
class ActionCable::SubscriptionAdapter::BaseTest < ActionCable::TestCase
## TEST THAT ERRORS ARE RETURNED FOR INHERITORS THAT DON'T OVERRIDE METHODS
class BrokenAdapter < ActionCable::StorageAdapter::Base
class BrokenAdapter < ActionCable::SubscriptionAdapter::Base
end
setup do
@server = TestServer.new
@server.config.storage_adapter = BrokenAdapter
@server.config.subscription_adapter = BrokenAdapter
@server.config.allowed_request_origins = %w( http://rubyonrails.com )
end