Created
June 23, 2017 15:14
-
-
Save rebelweb/231d1a68ecb233bc4d8b159a18aa0866 to your computer and use it in GitHub Desktop.
Decorator using simple delegator that follows most of draper syntax
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
require 'delegate' | |
class ApplicationDecorator < SimpleDelegator | |
def self.decorate(instance) | |
return nil if instance.blank? | |
new instance | |
end | |
def self.decorate_collection(collection) | |
return [] if collection.nil? || collection.length.zero? | |
collection.map { |instance| new instance } | |
end | |
private | |
def h | |
ApplicationController.helpers | |
end | |
def r | |
Rails.application.routes.url_helpers | |
end | |
def object | |
__getobj__ | |
end | |
def company | |
Company.first | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I only used the basics of draper. The only change is this:
instead of this