Class: Alondra::PushController

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PushController.



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

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.



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

def channel_names
  @channel_names
end

#requestObject

Returns the value of attribute request.



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

def request
  @request
end

Instance Method Details

#_prefixesObject



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

def _prefixes
  ['application']
end

#action_nameObject



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

def action_name
  'push'
end

#render_push(options) ⇒ Object



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

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



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

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