Skip to content

Commit 3cdd192

Browse files
Allow overriding of render methods in keys_controller
1 parent b55f9df commit 3cdd192

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

README.adoc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ image:https://img.shields.io/codeclimate/maintainability/riboseinc/rails-keyserv
1111

1212
A generic Rails engine for serving most kinds of keys.
1313

14-
== Usage
15-
16-
How to use my plugin.
17-
1814
== Installation
1915

2016
Add this line to your application’s Gemfile:
@@ -105,6 +101,27 @@ endpoints:
105101
}
106102
----
107103

104+
== Usage
105+
106+
=== Override controllers and rendering methods
107+
108+
==== Keys Controller
109+
110+
* `#render_index`
111+
** `@composed` is the collection to render
112+
* `#render_show_json(key)`
113+
* `#render_show_ext(key)`
114+
115+
==== Default settings for mounted routes
116+
117+
[source,ruby]
118+
----
119+
# E.g. in config/routes.rb
120+
mount_keyserver at: 'ks', controllers: {
121+
keys: 'rails/keyserver/api/v1/keys',
122+
}
123+
----
124+
108125
== Contributing
109126

110127
First, thank you for contributing! We love pull requests from everyone.

app/controllers/rails/keyserver/api/v1/keys_controller.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def set_composed
2323
end
2424

2525
def index
26-
render json: @composed.all
26+
render_index
2727
end
2828

2929
def show
@@ -40,17 +40,31 @@ def show
4040

4141
respond_to do |format|
4242
format.json do
43-
render json: key
43+
render_show_json(key)
4444
end
4545

4646
# If .pub requested, send key.public as an attachment.
4747
format.send(RK::Key::PGP.extension) do
48-
render_options = {}
49-
render_options[:"#{RK::Key::PGP.extension}"] = key
50-
render render_options
48+
render_show_ext(key)
5149
end
5250
end
5351
end
52+
53+
protected
54+
55+
def render_index
56+
render json: @composed.all
57+
end
58+
59+
def render_show_json(key)
60+
render json: key
61+
end
62+
63+
def render_show_ext(key)
64+
render_options = {}
65+
render_options[:"#{RK::Key::PGP.extension}"] = key
66+
render render_options
67+
end
5468
end
5569
end
5670
end

0 commit comments

Comments
 (0)