Skip to content

Commit f697ec2

Browse files
committed
Merge pull request #356 from davidcollie/master
Hide controller methods from documentation
2 parents b67a3e0 + 94b18c4 commit f697ec2

File tree

9 files changed

+45
-4
lines changed

9 files changed

+45
-4
lines changed

README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ see
224224
meta
225225
Hash or array with custom metadata.
226226

227+
show
228+
Resource is hidden from documentation when set to false (true by default)
229+
227230
Example:
228231
~~~~~~~~
229232

@@ -236,6 +239,7 @@ Example:
236239
237240
# More complex example
238241
api :GET, "/users/:id", "Show user profile"
242+
show false
239243
error :code => 401, :desc => "Unauthorized"
240244
error :code => 404, :desc => "Not Found", :meta => {:anything => "you can think of"}
241245
param :session, String, :desc => "user is logged in", :required => true

app/views/apipie/apipies/index.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
</thead>
2929
<tbody>
3030
<% api[:methods].each do |m| %>
31+
<% if !m[:show] %>
32+
<% next %>
33+
<% end %>
3134
<% m[:apis].each do |a| %>
3235
<tr>
3336
<td>

app/views/apipie/apipies/plain.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<h4><a href='#<%= key %>'><%= resource[:name] %></a></h4>
33
<ul>
44
<% resource[:methods].each do |method| %>
5+
<% if !method[:show] %>
6+
<% next %>
7+
<% end %>
58
<li><a href='#<%= key %>-<%= method[:name] %>'><%= method[:name] %></a></li>
69
<% end %>
710
</ul>
@@ -26,6 +29,9 @@
2629
<div>
2730

2831
<% resource[:methods].each do |method| %>
32+
<% if !method[:show] %>
33+
<% next %>
34+
<% end %>
2935
<hr/>
3036

3137
<h3 id="<%= "#{key}-#{method[:name]}" %>">

app/views/apipie/apipies/resource.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<div class='accordion' id='accordion'>
3838

3939
<% @resource[:methods].each do |m| %>
40+
<% if !m[:show] %>
41+
<% next %>
42+
<% end %>
4043
<hr>
4144
<div class='pull-right small'>
4245
<a href='<%= m[:doc_url] %><%= @doc[:link_extension] %>'> >>> </a>

app/views/apipie/apipies/static.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<h4><a href='#<%= key %>'><%= resource[:name] %></a></h4>
33
<ul>
44
<% resource[:methods].each do |method| %>
5+
<% if !method[:show] %>
6+
<% next %>
7+
<% end %>
58
<li><a href='#<%= key %>-<%= method[:name] %>'><%= method[:name] %></a></li>
69
<% end %>
710
</ul>
@@ -34,6 +37,9 @@
3437
<div class='accordion' id='accordion'>
3538

3639
<% resource[:methods].each do |method| %>
40+
<% if !method[:show] %>
41+
<% next %>
42+
<% end %>
3743
<hr>
3844

3945
<ul class='breadcrumb' id='<%= key %>-<%= method[:name] %>'>

lib/apipie/dsl_definition.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def _apipie_dsl_data_init
3333
:see => [],
3434
:formats => nil,
3535
:api_versions => [],
36-
:meta => nil
36+
:meta => nil,
37+
:show => true
3738
}
3839
end
3940
end
@@ -111,6 +112,13 @@ def example(example) #:doc:
111112
_apipie_dsl_data[:examples] << example.strip_heredoc
112113
end
113114

115+
# Determine if the method should be included
116+
# in the documentation
117+
def show(show)
118+
return unless Apipie.active_dsl?
119+
_apipie_dsl_data[:show] = show
120+
end
121+
114122
# Describe whole resource
115123
#
116124
# Example:

lib/apipie/method_description.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(method, path, desc, options)
1717

1818
end
1919

20-
attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :metadata, :headers
20+
attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :metadata, :headers, :show
2121

2222
def initialize(method, resource, dsl_data)
2323
@method = method.to_s
@@ -49,6 +49,12 @@ def initialize(method, resource, dsl_data)
4949
end
5050
@params_ordered = ParamDescription.unify(@params_ordered)
5151
@headers = dsl_data[:headers]
52+
53+
@show = if dsl_data.has_key? :show
54+
dsl_data[:show]
55+
else
56+
true
57+
end
5258
end
5359

5460
def id
@@ -144,7 +150,8 @@ def to_json(lang=nil)
144150
:examples => @examples,
145151
:metadata => @metadata,
146152
:see => see.map(&:to_json),
147-
:headers => headers
153+
:headers => headers,
154+
:show => @show
148155
}
149156
end
150157

spec/controllers/users_controller_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ def reload_controllers
402402
context "the key is valid" do
403403
it "should contain reference to another method" do
404404
api = Apipie[UsersController, :see_another]
405+
api.show.should == false
405406
see = api.see.first
406407
see.see_url.should == Apipie[UsersController, :create].doc_url
407408
see.link.should == 'development#users#create'
@@ -571,6 +572,7 @@ def reload_controllers
571572
:expected_type=>"numeric"},
572573
],
573574
:name => 'two_urls',
575+
:show => true,
574576
:apis => [
575577
{
576578
:http_method => 'GET',

spec/dummy/app/controllers/users_controller.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class UsersController < ApplicationController
169169
More builder documentation can be found at http://builder.rubyforge.org.
170170
eos
171171
api :GET, "/users/:id", "Show user profile"
172+
show false
172173
formats ['json', 'jsonp']
173174
error 401, "Unauthorized"
174175
error :code => 404, :description => "Not Found"
@@ -256,9 +257,10 @@ def two_urls
256257
end
257258

258259
api :GET, '/users/see_another', 'Boring method'
260+
show false
259261
see 'development#users#create'
260262
see 'development#users#index', "very interesting method reference"
261-
desc 'This method is boring, look at users#create'
263+
desc 'This method is boring, look at users#create. It is hidden from documentation.'
262264
def see_another
263265
render :text => 'This is very similar to create action'
264266
end

0 commit comments

Comments
 (0)