diaspora/app/presenters/base_presenter.rb
Florian Staudacher fba3092c61 * cleanup people_controller#show, add people_controller#stream for json
* introduce new presenters and extend the functionality of the BasePresenter
* add a handlebars template for the profile sidebar, render it everytime we need to update
* introduce a 'aspect_membership:update' global event
2014-09-15 01:37:23 +02:00

29 lines
615 B
Ruby

class BasePresenter
attr_reader :current_user
class << self
def new(*args)
return NilPresenter.new if args[0].nil?
super *args
end
def as_collection(collection, method=:as_json, *args)
collection.map{|object| self.new(object, *args).send(method) }
end
end
def initialize(presentable, curr_user=nil)
@presentable = presentable
@current_user = curr_user
end
def method_missing(method, *args)
@presentable.send(method, *args) if @presentable.respond_to?(method)
end
class NilPresenter
def method_missing(method, *args)
nil
end
end
end