socialforge/app/api/mobile/entities/comment.rb

30 lines
770 B
Ruby

module Mobile
module Entities
class Comment < Grape::Entity
include Redmine::I18n
def self.comment_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
f[field]
elsif f.is_a?(::Comment)
if f.respond_to?(field)
if field == :created_on
time_from_now(f.send(field))
else
f.send(field)
end
end
end
end
end
comment_expose :id
expose :author, using: Mobile::Entities::User do |c, opt|
if c.is_a? ::Comment
c.author
end
end
comment_expose :comments
comment_expose :created_on
end
end
end