trabajo-afectivo/lib/sessions/event.rb

25 lines
554 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
instance = backend.new(data, session, client_id)
pre = instance.pre
return pre if pre
2015-11-10 14:05:29 +00:00
ActiveRecord::Base.establish_connection
result = instance.run
2015-11-10 14:05:29 +00:00
ActiveRecord::Base.remove_connection
post = instance.post
return post if post
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