A middleware for Grape to allow working with Oink
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.ruby-gemset
.ruby-version
Gemfile
Gemfile.lock
LICENSE
README.md
grape-oink-0.0.2.gem
grape-oink.gemspec

README.md

Overview

The grape-oink gem provides a way to use the Oink library with Grape.

Requirements

  • Grape >= 0.10.0

Usage

Build and Install

To use, just install the gem from RubyGems or via Bundler by requiring it in your Gemfile.

gem 'grape-oink'

Middleware Setup

In your Grape API, install the middleware which will translate Grape endpoints to what Oink expects.

use Grape::Middleware::OinkMiddleware

Set up the Oink middleware. The below example is in config.ru of a generic Rack project.

require 'oink'
oink_path = File.expand_path('../log/oink.log', __FILE__)
use Oink::Middleware, :logger => Hodel3000CompliantLogger.new(oink_path)

Endpoint translation

Oink expects Rails-style endpoints where there is a controller and an action. Grape is more flexible than Oink in what these can be, so a few translation rules were added to make Oink happy.

The controller name might be namespaced. In this case, only the last class will be used in snakecase. This may change later.

My::Name::Space::UserObjects --> 'user_objects'

Certain tokens in the action are replaced.

Token Replacement
':' 'col_'
'/' 'sl_'

An example of a translation would be:

/:id --> sl_col_id

TODO

  • Include endpoint method in the action name. Oink doesn't seem to support method out of the box.