trabajo-afectivo/lib/sessions/event.rb

28 lines
711 B
Ruby
Raw Normal View History

2015-11-10 14:01:04 +00:00
class Sessions::Event
include ApplicationLib
2015-12-09 13:09:37 +00:00
def self.run(params)
adapter = "Sessions::Event::#{params[:event].to_classname}"
2015-11-10 14:05:29 +00:00
begin
backend = load_adapter(adapter)
rescue => e
Rails.logger.error e.inspect
Rails.logger.error e.backtrace
return { event: 'error', data: { error: "No such event #{params[:event]}: #{e.inspect}", payload: params[:payload] } }
2015-11-10 14:05:29 +00:00
end
2015-11-10 14:01:04 +00:00
begin
instance = backend.new(params)
result = instance.run
instance.destroy
result
rescue => e
Rails.logger.error e.inspect
Rails.logger.error e.backtrace
return { event: 'error', data: { error: e.message, payload: params[:payload] } }
end
2015-11-10 14:01:04 +00:00
end
2015-11-10 14:05:29 +00:00
end