Skip to content

Commit

Permalink
Allow overriding of render methods in keys_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ribose-jeffreylau committed May 27, 2019
1 parent b55f9df commit 3cdd192
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
25 changes: 21 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 19 additions & 5 deletions app/controllers/rails/keyserver/api/v1/keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def set_composed
end

def index
render json: @composed.all
render_index
end

def show
Expand All @@ -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
Expand Down

0 comments on commit 3cdd192

Please sign in to comment.