asciinema.org/app/serializers/asciicast_serializer.rb

50 lines
810 B
Ruby
Raw Normal View History

class AsciicastSerializer < ActiveModel::Serializer
self.root = false
2013-08-13 17:49:48 +00:00
attributes :id, :url, :snapshot, :width, :height
def id
object.to_param
end
2015-12-22 17:40:20 +00:00
def url
if v0_url?
2015-12-22 17:40:20 +00:00
object.stdout_frames_url
else
2016-04-10 15:12:35 +00:00
url = object.data.url
if url.starts_with?("/")
asciicast_path(object, format: :json) # download URL for local carrierwave store
else
url # direct signed S3 URL (because XHR CORS redirect doesn't work under Safari)
end
2015-12-22 17:40:20 +00:00
end
end
def private?
object.private?
end
def title
object.title
end
def author_display_name
object.user.display_name
end
def author_url
object.user.url
end
def author_avatar_url
object.user.avatar_url(object.user)
end
2015-12-22 17:40:20 +00:00
private
def v0_url?
!!@options[:v0]
2015-12-22 17:40:20 +00:00
end
2013-08-13 17:49:48 +00:00
end