Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Minor stylistic refactorings

  • Loading branch information...
commit 6862caf9e4b3ff894e3a5fe1d61bd69ba3d8d56c 1 parent 839092d
Alberto Fernández-Capel authored
19 lib/alondra.rb
View
@@ -58,19 +58,18 @@ def self.start_server_in_new_thread!
end
def self.start_server!
+
+ start_server_proc = Proc.new do
+ MessageQueue.instance.start_listening
+ Server.run
+ die_gracefully_on_signal
+ end
+
if EM.reactor_running?
- EM.schedule do
- MessageQueue.instance.start_listening
- Server.run
- end
+ EM.schedule(start_server_proc)
else
Log.info "starting EM reactor"
-
- EM.run do
- MessageQueue.instance.start_listening
- Server.run
- end
- die_gracefully_on_signal
+ EM.run(start_server_proc)
end
end
10 lib/alondra/command.rb
View
@@ -27,10 +27,12 @@ def execute!
end
def fire_event(event_type)
- event_hash = {:event => event_type,
- :resource => @connection.session,
- :resource_type => @connection.session.class.name,
- :channel => @channel_name}
+ event_hash = {
+ :event => event_type,
+ :resource => @connection.session,
+ :resource_type => @connection.session.class.name,
+ :channel => @channel_name
+ }
Event.new(event_hash, nil, connection).fire!
end
35 lib/alondra/event.rb
View
@@ -11,20 +11,8 @@ def initialize(event_hash, from_json = nil, connection = nil)
@type = event_hash[:event].to_sym
@json_encoded = from_json
- if Hash === event_hash[:resource]
- @resource = fetch(event_hash[:resource_type], event_hash[:resource])
- else
- @resource = event_hash[:resource]
- end
-
- @resource_type = event_hash[:resource_type] || resource.class.name
-
- if event_hash[:channel].present?
- @channel_name = event_hash[:channel]
- else
- channel_type = type == :updated ? :member : :collection
- Channel.default_name_for(resource, channel_type)
- end
+ set_resource_from(event_hash)
+ set_channel_from(event_hash)
end
def channel
@@ -70,5 +58,24 @@ def fetch(resource_type_name, attributes)
resource.assign_attributes(filtered_attributes, :without_protection => true)
resource
end
+
+ def set_resource_from(event_hash)
+ if Hash === event_hash[:resource]
+ @resource = fetch(event_hash[:resource_type], event_hash[:resource])
+ else
+ @resource = event_hash[:resource]
+ end
+
+ @resource_type = event_hash[:resource_type] || resource.class.name
+ end
+
+ def set_channel_from(event_hash)
+ if event_hash[:channel].present?
+ @channel_name = event_hash[:channel]
+ else
+ channel_type = type == :updated ? :member : :collection
+ Channel.default_name_for(resource, channel_type)
+ end
+ end
end
end
4 lib/alondra/push_controller.rb
View
@@ -21,8 +21,8 @@ def initialize(context, to, request = nil)
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')
+ 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)
Please sign in to comment.
Something went wrong with that request. Please try again.