From 9877ddcc0c8644a7e66c1c384540c3e0328bd72e Mon Sep 17 00:00:00 2001 From: namusyaka Date: Sun, 10 Apr 2016 07:12:38 +0900 Subject: [PATCH] Introduce Route#hidden for use in grape-swagger --- lib/grape/router/route.rb | 9 +++++++++ spec/grape/api_spec.rb | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/grape/router/route.rb b/lib/grape/router/route.rb index caf855ebd4..30a01ee6d0 100644 --- a/lib/grape/router/route.rb +++ b/lib/grape/router/route.rb @@ -57,6 +57,15 @@ def route_path pattern.path end + def hidden + @options[:hidden] || (settings[:description] && settings[:description][:hidden]) + end + + def route_hidden + warn_route_methods(:hidden, caller(1).shift) + hidden + end + def initialize(method, pattern, options = {}) @suffix = options[:suffix] @options = options.merge(method: method.to_s.upcase) diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index b293953018..f500383599 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -2277,6 +2277,16 @@ def static { description: 'second method', params: {} } ] end + it 'describes hidden accessor' do + subject.desc 'hidden as a description', hidden: true + subject.get :first do; end + subject.desc 'hidden as a route option' + subject.get :first, hidden: true do; end + first = subject.routes.shift + second = subject.routes.shift + expect(first.hidden).to be_truthy + expect(second.hidden).to be_truthy + end it 'resets desc' do subject.desc 'first method' subject.get :first do; end