Class: ActionCable::Server::Configuration

Inherits:
Object
  • Object
show all
Defined in:
actioncable/lib/action_cable/server/configuration.rb

Overview

Экземпляр этого объекта конфигурации доступен через ActionCable.server.config, который позволяет вам настроить конфигурацию Action Cable в config/initializers вашего приложения Rails.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.


11
12
13
14
15
16
17
18
19
# File 'actioncable/lib/action_cable/server/configuration.rb', line 11

def initialize
  @log_tags = []

  @connection_class = -> { ActionCable::Connection::Base }
  @worker_pool_size = 4

  @disable_request_forgery_protection = false
  @allow_same_origin_as_host = true
end

Instance Attribute Details

#allow_same_origin_as_hostObject

Returns the value of attribute allow_same_origin_as_host


8
9
10
# File 'actioncable/lib/action_cable/server/configuration.rb', line 8

def allow_same_origin_as_host
  @allow_same_origin_as_host
end

#allowed_request_originsObject

Returns the value of attribute allowed_request_origins


8
9
10
# File 'actioncable/lib/action_cable/server/configuration.rb', line 8

def allowed_request_origins
  @allowed_request_origins
end

#cableObject

Returns the value of attribute cable


9
10
11
# File 'actioncable/lib/action_cable/server/configuration.rb', line 9

def cable
  @cable
end

#connection_classObject

Returns the value of attribute connection_class


7
8
9
# File 'actioncable/lib/action_cable/server/configuration.rb', line 7

def connection_class
  @connection_class
end

#disable_request_forgery_protectionObject

Returns the value of attribute disable_request_forgery_protection


8
9
10
# File 'actioncable/lib/action_cable/server/configuration.rb', line 8

def disable_request_forgery_protection
  @disable_request_forgery_protection
end

#log_tagsObject

Returns the value of attribute log_tags


6
7
8
# File 'actioncable/lib/action_cable/server/configuration.rb', line 6

def log_tags
  @log_tags
end

#loggerObject

Returns the value of attribute logger


6
7
8
# File 'actioncable/lib/action_cable/server/configuration.rb', line 6

def logger
  @logger
end

#mount_pathObject

Returns the value of attribute mount_path


9
10
11
# File 'actioncable/lib/action_cable/server/configuration.rb', line 9

def mount_path
  @mount_path
end

#urlObject

Returns the value of attribute url


9
10
11
# File 'actioncable/lib/action_cable/server/configuration.rb', line 9

def url
  @url
end

#use_fayeObject

Returns the value of attribute use_faye


7
8
9
# File 'actioncable/lib/action_cable/server/configuration.rb', line 7

def use_faye
  @use_faye
end

#worker_pool_sizeObject

Returns the value of attribute worker_pool_size


7
8
9
# File 'actioncable/lib/action_cable/server/configuration.rb', line 7

def worker_pool_size
  @worker_pool_size
end

Instance Method Details

#client_socket_classObject


48
49
50
51
52
53
54
# File 'actioncable/lib/action_cable/server/configuration.rb', line 48

def client_socket_class
  if use_faye
    ActionCable::Connection::FayeClientSocket
  else
    ActionCable::Connection::ClientSocket
  end
end

#event_loop_classObject


40
41
42
43
44
45
46
# File 'actioncable/lib/action_cable/server/configuration.rb', line 40

def event_loop_class
  if use_faye
    ActionCable::Connection::FayeEventLoop
  else
    ActionCable::Connection::StreamEventLoop
  end
end

#pubsub_adapterObject

Возвращает константу адаптера подписки, указанного в файле config/cable.yml. Если адаптер не может быть найден, по умолчанию будет установлен адаптер Redis. Также гарантирует правильность необходимых зависимостей.


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'actioncable/lib/action_cable/server/configuration.rb', line 24

def pubsub_adapter
  adapter = (cable.fetch('adapter') { 'redis' })
  path_to_adapter = "action_cable/subscription_adapter/#{adapter}"
  begin
    require path_to_adapter
  rescue Gem::LoadError => e
    raise Gem::LoadError, "Specified '#{adapter}' for Action Cable pubsub adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by Action Cable)."
  rescue LoadError => e
    raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter in config/cable.yml is valid. If you use an adapter other than 'postgresql' or 'redis' add the necessary adapter gem to the Gemfile.", e.backtrace
  end

  adapter = adapter.camelize
  adapter = 'PostgreSQL' if adapter == 'Postgresql'
  "ActionCable::SubscriptionAdapter::#{adapter}".constantize
end