2011-11-16 00:39:16 +00:00
|
|
|
class Locomotive::BasePresenter
|
|
|
|
|
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
|
|
|
include ActionView::Helpers::TextHelper
|
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
attr_reader :source, :options, :ability
|
2011-11-16 00:39:16 +00:00
|
|
|
|
2011-11-21 01:27:05 +00:00
|
|
|
delegate :created_at, :updated_at, :to => :source
|
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
def initialize(object, options = {})
|
|
|
|
@source = object
|
|
|
|
@options = options
|
|
|
|
|
|
|
|
if @options && @options[:current_account] && @options[:current_site]
|
|
|
|
@ability = Locomotive::Ability.new @options[:current_account], @options[:current_site]
|
|
|
|
end
|
2011-11-16 00:39:16 +00:00
|
|
|
end
|
|
|
|
|
2011-11-19 14:47:56 +00:00
|
|
|
def id
|
|
|
|
@source._id.to_s
|
|
|
|
end
|
|
|
|
|
2011-11-29 13:58:19 +00:00
|
|
|
def ability?
|
|
|
|
self.ability.present?
|
|
|
|
end
|
|
|
|
|
2011-11-21 01:27:05 +00:00
|
|
|
def included_methods
|
|
|
|
%w(id created_at updated_at)
|
|
|
|
end
|
|
|
|
|
|
|
|
def as_json
|
|
|
|
{}.tap do |hash|
|
|
|
|
self.included_methods.map(&:to_sym).each do |meth|
|
|
|
|
hash[meth] = self.send(meth) rescue nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-11-16 00:39:16 +00:00
|
|
|
|
|
|
|
end
|