Project

grape-oink

0.0
No commit activity in last 3 years
No release in over 3 years
A middleware for Grape to allow working with Oink.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 0.10.0
~> 3.0
 Project Readme

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.