diff --git a/README.adoc b/README.adoc index 1efb5d7..2dfab8e 100644 --- a/README.adoc +++ b/README.adoc @@ -11,10 +11,6 @@ image:https://img.shields.io/codeclimate/maintainability/riboseinc/rails-keyserv A generic Rails engine for serving most kinds of keys. -== Usage - -How to use my plugin. - == Installation Add this line to your application’s Gemfile: @@ -105,6 +101,27 @@ endpoints: } ---- +== Usage + +=== Override controllers and rendering methods + +==== Keys Controller + +* `#render_index` +** `@composed` is the collection to render +* `#render_show_json(key)` +* `#render_show_ext(key)` + +==== Default settings for mounted routes + +[source,ruby] +---- +# E.g. in config/routes.rb +mount_keyserver at: 'ks', controllers: { + keys: 'rails/keyserver/api/v1/keys', +} +---- + == Contributing First, thank you for contributing! We love pull requests from everyone. diff --git a/app/controllers/rails/keyserver/api/v1/keys_controller.rb b/app/controllers/rails/keyserver/api/v1/keys_controller.rb index fdd431b..022f113 100644 --- a/app/controllers/rails/keyserver/api/v1/keys_controller.rb +++ b/app/controllers/rails/keyserver/api/v1/keys_controller.rb @@ -23,7 +23,7 @@ def set_composed end def index - render json: @composed.all + render_index end def show @@ -40,17 +40,31 @@ def show respond_to do |format| format.json do - render json: key + render_show_json(key) end # If .pub requested, send key.public as an attachment. format.send(RK::Key::PGP.extension) do - render_options = {} - render_options[:"#{RK::Key::PGP.extension}"] = key - render render_options + render_show_ext(key) end end end + + protected + + def render_index + render json: @composed.all + end + + def render_show_json(key) + render json: key + end + + def render_show_ext(key) + render_options = {} + render_options[:"#{RK::Key::PGP.extension}"] = key + render render_options + end end end end