Class: Alondra::PushController

Inherits:
Object
  • Object
show all
Includes:
AbstractController::AssetPaths, AbstractController::Helpers, AbstractController::Logger, AbstractController::Rendering, AbstractController::Translation, ActiveSupport::Configurable
Defined in:
lib/alondra/push_controller.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, to, request = nil) ⇒ PushController

Returns a new instance of PushController.



15
16
17
18
19
20
21
# File 'lib/alondra/push_controller.rb', line 15

def initialize(context, to, request = nil)
  @channel_names = Channel.names_for(to)
  @request = request

  self.class.view_paths = ActionController::Base.view_paths
  copy_instance_variables_from(context)
end

Instance Attribute Details

#channel_namesObject

Returns the value of attribute channel_names.



12
13
14
# File 'lib/alondra/push_controller.rb', line 12

def channel_names
  @channel_names
end

#requestObject

Returns the value of attribute request.



13
14
15
# File 'lib/alondra/push_controller.rb', line 13

def request
  @request
end

Class Method Details

.protect_against_forgery?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/alondra/push_controller.rb', line 50

def self.protect_against_forgery?
  false
end

Instance Method Details

#_prefixesObject



34
35
36
# File 'lib/alondra/push_controller.rb', line 34

def _prefixes
  ['application']
end

#action_nameObject



42
43
44
# File 'lib/alondra/push_controller.rb', line 42

def action_name
  'push'
end

#protect_against_forgery?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/alondra/push_controller.rb', line 46

def protect_against_forgery?
  false
end

#render_push(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/alondra/push_controller.rb', line 23

def render_push(options)
  if EM.reactor_thread?
    Log.warn 'You are rendering a view from the Event Machine reactor thread'
    Log.warn 'Rendering a view is a possibly blocking operation, so be careful'
  end

  message_content = render_to_string(*options)
  msg = Message.new(message_content, channel_names)
  msg.enqueue
end

#view_pathsObject



38
39
40
# File 'lib/alondra/push_controller.rb', line 38

def view_paths
  @view_paths ||= ApplicationController.send '_view_paths'
end