From 79e382ce0b22dac2e413cdbb091c2ed07a987a7e Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sat, 15 Sep 2012 12:06:33 +0200 Subject: [PATCH] add services --- lib/travis/api/app.rb | 4 ++++ lib/travis/api/app/endpoint.rb | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/travis/api/app.rb b/lib/travis/api/app.rb index 36d1f1d8..1b2b7230 100644 --- a/lib/travis/api/app.rb +++ b/lib/travis/api/app.rb @@ -75,6 +75,10 @@ class Travis::Api::App def self.setup_travis Travis::Database.connect + + Travis::Services.constants.each do |name| + Travis.services[name.to_s.underscore.to_sym] = Travis::Services.const_get(name) unless name == :Base + end end def self.load_endpoints diff --git a/lib/travis/api/app/endpoint.rb b/lib/travis/api/app/endpoint.rb index 9d96435f..6fc5ced8 100644 --- a/lib/travis/api/app/endpoint.rb +++ b/lib/travis/api/app/endpoint.rb @@ -10,5 +10,12 @@ class Travis::Api::App before { content_type :json } error(ActiveRecord::RecordNotFound, Sinatra::NotFound) { not_found } not_found { content_type =~ /json/ ? { 'file' => 'not found' } : 'file not found' } + + private + + def service(key) + const = Travis.services[key] || raise("no service registered for #{key}") + const.new(respond_to?(:current_user) ? current_user : nil) + end end end