Class: CableX::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/cable_x/engine.rb

Overview

CableX Engine

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#allowed_request_originsObject

Returns the value of attribute allowed_request_origins.



11
12
13
# File 'lib/cable_x/engine.rb', line 11

def allowed_request_origins
  @allowed_request_origins
end

Class Method Details

.serverObject



14
15
16
17
18
19
20
# File 'lib/cable_x/engine.rb', line 14

def self.server
  setup_rate_limiting
  server = CableX::Server.server
  server.config.connection_class = -> { CableX::Cable::Connection }
  server.config.allowed_request_origins = allowed_request_origins
  server
end

.setup_rate_limitingObject



22
23
24
25
26
27
28
29
30
# File 'lib/cable_x/engine.rb', line 22

def self.setup_rate_limiting
  cable_config = Rails.application.config_for(:cable) rescue nil
  cable_x_config = Rails.application.config_for(:cable_x) rescue nil
  self.allowed_request_origins = cable_x_config[:allowed_request_origins]
  return unless cable_x_config && cable_config && cable_config[:adapter] == 'redis'

  CableX::Cable::Connection.redis_config = cable_config
  CableX::Cable::Connection.rate_limit = cable_x_config[:rate_limit]
end