v3: get rid of service helper mixins

This commit is contained in:
Konstantin Haase 2015-02-18 13:12:13 +01:00
parent bc638ccb19
commit bd4d6b91b4
7 changed files with 9 additions and 40 deletions

View File

@ -1,9 +1,5 @@
module Travis::API::V3
class Service
def self.helpers(*list)
include(*list.map { |e| ServiceHelpers[e] })
end
def self.result_type(type = nil)
@result_type = type if type
@result_type ||= parent.result_type if parent and parent.respond_to? :result_type
@ -23,6 +19,12 @@ module Travis::API::V3
@queries[type] ||= Queries[type].new(params)
end
def find(type = self.class.result_type, *args)
not_found(true, type) unless object = query(type).find(*args)
not_found(false, type) unless access_control.visible? object
object
end
def not_found(actually_not_found = false, type = nil)
type, actually_not_found = actually_not_found, false if actually_not_found.is_a? Symbol
error = actually_not_found ? EntityMissing : NotFound

View File

@ -1,13 +0,0 @@
module Travis::API::V3
module ServiceHelpers::Organization
def organization
@organization ||= find_organization
end
def find_organization
not_found(true, :organization) unless org = query(:organization).find
not_found(false, :organization) unless access_control.visible? org
org
end
end
end

View File

@ -1,13 +0,0 @@
module Travis::API::V3
module ServiceHelpers::Repository
def repository
@repository ||= find_repository
end
def find_repository
not_found(true, :repository) unless repo = query(:repository).find
not_found(false, :repository) unless access_control.visible? repo
repo
end
end
end

View File

@ -1,9 +1,7 @@
module Travis::API::V3
class Services::Organization::Find < Service
helpers :organization
def run!
organization
find
end
end
end

View File

@ -1,9 +1,7 @@
module Travis::API::V3
class Services::Repository::Find < Service
helpers :repository
def run!
repository
find
end
end
end

View File

@ -1,10 +1,8 @@
module Travis::API::V3
class Services::Requests::Create < Service
helpers :repository
def run
not_implemented
query.schedule_for(repository)
query.schedule_for(find(:repository))
accepted
end
end

View File

@ -1,5 +1,4 @@
module Travis::API::V3
class Services::Requests::Find < Service
helpers :repository
end
end