Skip to content
This repository
Browse code

Minor stylistic refactorings

  • Loading branch information...
commit 6862caf9e4b3ff894e3a5fe1d61bd69ba3d8d56c 1 parent 839092d
Alberto Fernández-Capel authored
19 lib/alondra.rb
@@ -58,19 +58,18 @@ def self.start_server_in_new_thread!
58 58 end
59 59
60 60 def self.start_server!
  61 +
  62 + start_server_proc = Proc.new do
  63 + MessageQueue.instance.start_listening
  64 + Server.run
  65 + die_gracefully_on_signal
  66 + end
  67 +
61 68 if EM.reactor_running?
62   - EM.schedule do
63   - MessageQueue.instance.start_listening
64   - Server.run
65   - end
  69 + EM.schedule(start_server_proc)
66 70 else
67 71 Log.info "starting EM reactor"
68   -
69   - EM.run do
70   - MessageQueue.instance.start_listening
71   - Server.run
72   - end
73   - die_gracefully_on_signal
  72 + EM.run(start_server_proc)
74 73 end
75 74 end
76 75
10 lib/alondra/command.rb
@@ -27,10 +27,12 @@ def execute!
27 27 end
28 28
29 29 def fire_event(event_type)
30   - event_hash = {:event => event_type,
31   - :resource => @connection.session,
32   - :resource_type => @connection.session.class.name,
33   - :channel => @channel_name}
  30 + event_hash = {
  31 + :event => event_type,
  32 + :resource => @connection.session,
  33 + :resource_type => @connection.session.class.name,
  34 + :channel => @channel_name
  35 + }
34 36
35 37 Event.new(event_hash, nil, connection).fire!
36 38 end
35 lib/alondra/event.rb
@@ -11,20 +11,8 @@ def initialize(event_hash, from_json = nil, connection = nil)
11 11 @type = event_hash[:event].to_sym
12 12 @json_encoded = from_json
13 13
14   - if Hash === event_hash[:resource]
15   - @resource = fetch(event_hash[:resource_type], event_hash[:resource])
16   - else
17   - @resource = event_hash[:resource]
18   - end
19   -
20   - @resource_type = event_hash[:resource_type] || resource.class.name
21   -
22   - if event_hash[:channel].present?
23   - @channel_name = event_hash[:channel]
24   - else
25   - channel_type = type == :updated ? :member : :collection
26   - Channel.default_name_for(resource, channel_type)
27   - end
  14 + set_resource_from(event_hash)
  15 + set_channel_from(event_hash)
28 16 end
29 17
30 18 def channel
@@ -70,5 +58,24 @@ def fetch(resource_type_name, attributes)
70 58 resource.assign_attributes(filtered_attributes, :without_protection => true)
71 59 resource
72 60 end
  61 +
  62 + def set_resource_from(event_hash)
  63 + if Hash === event_hash[:resource]
  64 + @resource = fetch(event_hash[:resource_type], event_hash[:resource])
  65 + else
  66 + @resource = event_hash[:resource]
  67 + end
  68 +
  69 + @resource_type = event_hash[:resource_type] || resource.class.name
  70 + end
  71 +
  72 + def set_channel_from(event_hash)
  73 + if event_hash[:channel].present?
  74 + @channel_name = event_hash[:channel]
  75 + else
  76 + channel_type = type == :updated ? :member : :collection
  77 + Channel.default_name_for(resource, channel_type)
  78 + end
  79 + end
73 80 end
74 81 end
4 lib/alondra/push_controller.rb
@@ -21,8 +21,8 @@ def initialize(context, to, request = nil)
21 21
22 22 def render_push(options)
23 23 if EM.reactor_thread?
24   - Log.warn('You are rendering a view from the Event Machine reactor thread')
25   - Log.warn('Rendering a view is a possibly blocking operation, so be careful')
  24 + Log.warn 'You are rendering a view from the Event Machine reactor thread'
  25 + Log.warn 'Rendering a view is a possibly blocking operation, so be careful'
26 26 end
27 27
28 28 message_content = render_to_string(*options)

0 comments on commit 6862caf

Please sign in to comment.
Something went wrong with that request. Please try again.