Last active
August 29, 2015 14:16
-
-
Save hosh/e39d135862d5fc857757 to your computer and use it in GitHub Desktop.
A neat thing you can do with Intermodal + functional Ruby
This file contains 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
require 'rlet/functional' | |
module SomeApi | |
module API | |
class V1_0 < Intermodal::API | |
using RLet::Functional | |
self.default_per_page = 25 | |
map_data do | |
attribute = ->(field) { ->(r) { r.send(field) } } | |
helper = ->(_method) { ActionController::Base.helpers.method(_method) } | |
presentation_for :book do | |
presents :id | |
presents :price, with: attribute.(:price) | helper.(:number_to_currency) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@brandondees to expand further on what I mean by "flexible", the
|
is an applicative operator. That means you can chain functions along the lines of:presents :price, with: attribute.(:price) | locale.(:fr) | helper.(:number_to_currency)
as an example.