Created
June 16, 2012 20:03
-
-
Save reu/2942384 to your computer and use it in GitHub Desktop.
Simplest "presenter" ever
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
class Presenter < BasicObject | |
def initialize(object) | |
@object = object | |
end | |
def method_missing(method, *args, &block) | |
@object.send method, *args, &block | |
end | |
module RailsHelpers | |
private | |
def t(*args, &block) | |
I18n.t(*args, &block) | |
end | |
def l(*args, &block) | |
I18n.l(*args, &block) | |
end | |
def r | |
Rails.application.routes.url_helpers | |
end | |
def h | |
ApplicationController.helpers | |
end | |
end | |
end | |
class UserPresenter < Presenter | |
include RailsHelpers | |
def link | |
h.link_to name, r.user_path(@object) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment