trabajo-afectivo/lib/sessions/event.rb

30 lines
627 B
Ruby
Raw Normal View History

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-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
ActiveRecord::Base.establish_connection
instance = backend.new(data, session, client_id)
pre = instance.pre
if pre
ActiveRecord::Base.remove_connection
return pre
end
result = instance.run
post = instance.post
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