Created
February 22, 2018 10:20
-
-
Save Irostovsky/9d6431342b16a3b2abf09971b37b2db2 to your computer and use it in GitHub Desktop.
Decorator for the PORO
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 FooPresenter | |
include Draper::Decoratable | |
attr_accessor :user | |
def initialize(user) | |
@user = user | |
end | |
def name | |
user.name | |
end | |
def price | |
123 | |
end | |
end | |
class FooPresenterDecorator < Draper::Decorator | |
delegate_all | |
def name | |
object.name.upcase | |
end | |
def price | |
h.number_to_currency object.price | |
end | |
end | |
FooPresenter.new(User.first).decorate.price | |
> "£123.00" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment