v3: get rid of service helper mixins
This commit is contained in:
parent
bc638ccb19
commit
bd4d6b91b4
|
@ -1,9 +1,5 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Service
|
class Service
|
||||||
def self.helpers(*list)
|
|
||||||
include(*list.map { |e| ServiceHelpers[e] })
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.result_type(type = nil)
|
def self.result_type(type = nil)
|
||||||
@result_type = type if type
|
@result_type = type if type
|
||||||
@result_type ||= parent.result_type if parent and parent.respond_to? :result_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)
|
@queries[type] ||= Queries[type].new(params)
|
||||||
end
|
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)
|
def not_found(actually_not_found = false, type = nil)
|
||||||
type, actually_not_found = actually_not_found, false if actually_not_found.is_a? Symbol
|
type, actually_not_found = actually_not_found, false if actually_not_found.is_a? Symbol
|
||||||
error = actually_not_found ? EntityMissing : NotFound
|
error = actually_not_found ? EntityMissing : NotFound
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
|
@ -1,9 +1,7 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Organization::Find < Service
|
class Services::Organization::Find < Service
|
||||||
helpers :organization
|
|
||||||
|
|
||||||
def run!
|
def run!
|
||||||
organization
|
find
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Repository::Find < Service
|
class Services::Repository::Find < Service
|
||||||
helpers :repository
|
|
||||||
|
|
||||||
def run!
|
def run!
|
||||||
repository
|
find
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Requests::Create < Service
|
class Services::Requests::Create < Service
|
||||||
helpers :repository
|
|
||||||
|
|
||||||
def run
|
def run
|
||||||
not_implemented
|
not_implemented
|
||||||
query.schedule_for(repository)
|
query.schedule_for(find(:repository))
|
||||||
accepted
|
accepted
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Requests::Find < Service
|
class Services::Requests::Find < Service
|
||||||
helpers :repository
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user