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

34 lines
955 B
Ruby

module Mobile
module Entities
class Attachment < Grape::Entity
include Redmine::I18n
def self.attachment_expose(field)
expose field do |f,opt|
if f.is_a?(Hash) && f.key?(field)
f[field]
elsif f.is_a?(::Attachment)
if f.respond_to?(field)
if field == :created_on
format_time(f.send(field))
else
f.send(field)
end
else
case field
when :file_dir
"attachments/download/" << f.send(:id).to_s << '/'
end
end
end
end
end
attachment_expose :id
attachment_expose :filename
attachment_expose :description
attachment_expose :downloads
attachment_expose :quotes
attachment_expose :created_on
attachment_expose :file_dir
end
end
end