2015-11-10 14:01:04 +00:00
|
|
|
class Sessions::Event
|
|
|
|
include ApplicationLib
|
|
|
|
|
|
|
|
def self.run(event, data, session, client_id)
|
2015-11-10 14:05:29 +00:00
|
|
|
adapter = "Sessions::Event::#{event.to_classname}"
|
2015-11-12 07:51:52 +00:00
|
|
|
|
2015-11-10 14:05:29 +00:00
|
|
|
begin
|
|
|
|
backend = load_adapter(adapter)
|
|
|
|
rescue => e
|
|
|
|
return { error: "No such event #{event}" }
|
|
|
|
end
|
2015-11-10 14:01:04 +00:00
|
|
|
|
2015-11-12 10:28:06 +00:00
|
|
|
ActiveRecord::Base.establish_connection
|
2015-11-11 13:10:26 +00:00
|
|
|
instance = backend.new(data, session, client_id)
|
2015-11-12 07:51:52 +00:00
|
|
|
pre = instance.pre
|
2015-11-12 10:28:06 +00:00
|
|
|
if pre
|
|
|
|
ActiveRecord::Base.remove_connection
|
|
|
|
return pre
|
|
|
|
end
|
2015-11-11 13:10:26 +00:00
|
|
|
result = instance.run
|
2015-11-12 07:51:52 +00:00
|
|
|
post = instance.post
|
2015-11-12 10:28:06 +00:00
|
|
|
if post
|
|
|
|
ActiveRecord::Base.remove_connection
|
|
|
|
return post
|
|
|
|
end
|
2015-11-10 14:05:29 +00:00
|
|
|
result
|
2015-11-10 14:01:04 +00:00
|
|
|
end
|
|
|
|
|
2015-11-10 14:05:29 +00:00
|
|
|
end
|