Class: AnyCable::Rails::ConnectionFactory
- Inherits:
-
Object
- Object
- AnyCable::Rails::ConnectionFactory
- Defined in:
- lib/anycable/rails/connection_factory.rb
Instance Method Summary collapse
- #call(socket, **options) ⇒ Object
-
#initialize(&block) ⇒ ConnectionFactory
constructor
A new instance of ConnectionFactory.
- #map(route, &block) ⇒ Object
Constructor Details
#initialize(&block) ⇒ ConnectionFactory
Returns a new instance of ConnectionFactory.
27 28 29 30 31 |
# File 'lib/anycable/rails/connection_factory.rb', line 27 def initialize(&block) @mappings = [] @use_router = false instance_eval(&block) if block end |
Instance Method Details
#call(socket, **options) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/anycable/rails/connection_factory.rb', line 33 def call(socket, **) connection_class = use_router? ? resolve_connection_class(socket.env) : ActionCable.server.config.connection_class.call AnyCable::Rails::Connection.new(connection_class, socket, **) end |
#map(route, &block) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/anycable/rails/connection_factory.rb', line 40 def map(route, &block) raise ArgumentError, "Block is required" unless block @use_router = true mappings << [route, block] end |