From 0cdecaade3c6cb17239f10d5148f1226b9339295 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 21 May 2015 14:57:16 +0200 Subject: [PATCH] API v3: add captures route dsl method --- lib/travis/api/v3/routes.rb | 7 +++++-- lib/travis/api/v3/routes/dsl.rb | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/travis/api/v3/routes.rb b/lib/travis/api/v3/routes.rb index 81305aab..a828f295 100644 --- a/lib/travis/api/v3/routes.rb +++ b/lib/travis/api/v3/routes.rb @@ -15,8 +15,8 @@ module Travis::API::V3 end resource :repository do - route '/repo/({repository.id}|{repository.slug})', - capture: { :"repository.id" => :digit } + capture id: :digit, slug: %r{[^/]+%2[fF][^/]+} + route '/repo/({repository.id}|{repository.slug})' get :find post :enable, '/enable' @@ -40,17 +40,20 @@ module Travis::API::V3 end resource :build do + capture id: :digit route '/build/{build.id}' get :find end resource :user do + capture id: :digit route '/user' get :current get :find, '/{user.id}' end resource :organization do + capture id: :digit route '/org/{organization.id}' get :find end diff --git a/lib/travis/api/v3/routes/dsl.rb b/lib/travis/api/v3/routes/dsl.rb index e32a97ff..e71723d7 100644 --- a/lib/travis/api/v3/routes/dsl.rb +++ b/lib/travis/api/v3/routes/dsl.rb @@ -33,8 +33,23 @@ module Travis::API::V3 @current_resource = resource_was end - def route(value, options = {}) - current_resource.route = Mustermann.new(prefix) + Mustermann.new(value, options) + def route(value) + current_resource.route = mustermann(prefix) + mustermann(value) + end + + def mustermann(*input) + Mustermann.new(*input, **mustermann_options) + end + + def mustermann_options + @mustermann_options ||= { capture: {} } + end + + def capture(mapping) + mapping.each_pair do |key, value| + key = "#{current_resource.identifier}.#{key}" if current_resource and not key.to_s.include?(?.) + mustermann_options[:capture][key.to_sym] = value + end end def get(*args)