2011-11-23 21:30:09 +00:00
|
|
|
class Asciicast < ActiveRecord::Base
|
2012-12-18 20:38:49 +00:00
|
|
|
MAX_DELAY = 5.0
|
|
|
|
|
2013-08-04 20:39:55 +00:00
|
|
|
mount_uploader :stdin_data, StdinDataUploader
|
|
|
|
mount_uploader :stdin_timing, StdinTimingUploader
|
|
|
|
mount_uploader :stdout_data, StdoutDataUploader
|
|
|
|
mount_uploader :stdout_timing, StdoutTimingUploader
|
2013-09-20 21:21:25 +00:00
|
|
|
mount_uploader :stdout_frames, StdoutFramesUploader
|
2011-11-23 22:22:14 +00:00
|
|
|
|
2013-08-04 20:56:16 +00:00
|
|
|
serialize :snapshot, JSON
|
2013-07-08 22:55:31 +00:00
|
|
|
|
2013-08-04 20:39:55 +00:00
|
|
|
validates :stdout_data, :stdout_timing, :presence => true
|
2011-11-23 22:22:14 +00:00
|
|
|
validates :terminal_columns, :terminal_lines, :duration, :presence => true
|
2012-01-14 20:26:07 +00:00
|
|
|
|
2012-03-04 17:14:58 +00:00
|
|
|
belongs_to :user
|
2013-08-08 13:07:48 +00:00
|
|
|
has_many :comments, -> { order(:created_at) }, :dependent => :destroy
|
2012-04-06 12:06:40 +00:00
|
|
|
has_many :likes, :dependent => :destroy
|
2012-03-03 16:38:29 +00:00
|
|
|
|
2013-11-17 15:49:46 +00:00
|
|
|
scope :featured, -> { where(featured: true) }
|
|
|
|
scope :by_recency, -> { order("created_at DESC") }
|
|
|
|
scope :latest_limited, -> (n) { by_recency.limit(n).includes(:user) }
|
|
|
|
scope :latest_featured_limited, -> (n) {
|
|
|
|
featured.by_recency.limit(n).includes(:user)
|
|
|
|
}
|
2012-12-09 20:22:12 +00:00
|
|
|
|
2013-08-04 20:53:25 +00:00
|
|
|
attr_accessible :title, :description, :time_compression
|
2012-03-04 14:18:09 +00:00
|
|
|
|
2012-08-22 18:00:31 +00:00
|
|
|
def self.cache_key
|
|
|
|
timestamps = scoped.select(:updated_at).map { |o| o.updated_at.to_i }
|
|
|
|
Digest::MD5.hexdigest timestamps.join('/')
|
|
|
|
end
|
|
|
|
|
2013-08-04 20:43:36 +00:00
|
|
|
def stdout
|
2013-08-28 14:56:40 +00:00
|
|
|
@stdout ||= BufferedStdout.new(stdout_data.decompressed_path,
|
2013-09-10 19:29:17 +00:00
|
|
|
stdout_timing.decompressed_path).lazy
|
|
|
|
end
|
|
|
|
|
|
|
|
def with_terminal
|
|
|
|
terminal = Terminal.new(terminal_columns, terminal_lines)
|
|
|
|
yield(terminal)
|
|
|
|
ensure
|
2013-09-14 11:13:58 +00:00
|
|
|
terminal.release if terminal
|
2013-08-04 20:43:36 +00:00
|
|
|
end
|
|
|
|
|
2011-11-23 21:30:09 +00:00
|
|
|
end
|