Last active
May 11, 2016 10:12
-
-
Save fnordfish/ee26f406c20ceac286e2555c8bd1100c to your computer and use it in GitHub Desktop.
A Padrino (0.13.2) Initializer for Yaks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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