Skip to content

Instantly share code, notes, and snippets.

@fnordfish
Last active May 11, 2016 10:12
Show Gist options
  • Select an option

  • Save fnordfish/ee26f406c20ceac286e2555c8bd1100c to your computer and use it in GitHub Desktop.

Select an option

Save fnordfish/ee26f406c20ceac286e2555c8bd1100c to your computer and use it in GitHub Desktop.
A Padrino (0.13.2) Initializer for Yaks
# config/initializers/yaks.rb
require "yaks-sinatra"
# Usage:
# In your "app/app.rb": `register YaksInitializer`
module YaksInitializer
def self.registered(app)
# code run on application `register YaksInitializer`
# this code is run every time `app.rb` is reloaded
app.register Yaks::Sinatra
app.configure_yaks do
# @see: https://gist.github.com/fnordfish/4f5cbd11a4e76ed56914679eebc29510
# policy_class YaksSequel::Policy
default_format :json_api
rel_template "{rel}"
# use a global namespace for your mappers
mapper_namespace ::Mappers
# or app-agnostic namespaces (MyApp::Mappers)
# mapper_namespace app.const_get(:Mappers)
# JSON specification doesn't standardize time formats, so Yaks doesn't imply
# any as well, but in most cases it's best you use the global ISO8601 standard.
# Padrino 0.13.2 has no `ActiveSupport::TimeWithZone` by default (add when needed.)
map_to_primitive Date, Time, DateTime, &:iso8601
# Using Sequel and JSONB columns in Postgres?
# map_to_primitive Sequel::Postgres::JSONBHash do |jsonb_hash|
# Hash[jsonb_hash]
# end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment