Thibault Jouan 2f6a447416 Implement track/stream
* Add Streamer class
* Use FactoryGirl for factories
* Add sha256 field to tracks
* Add mime_type field to tracks
2011-07-26 16:59:47 +00:00

19 lines
410 B
Ruby

class Track < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :mime_type
validates_presence_of :sha256
def filepath
"#{Rails.root}/data/tracks/#{sha256}"
end
def save_with_file(file, mime_type)
self.sha256 = Digest::SHA256.file(file.path).hexdigest
self.mime_type = mime_type
File.open(filepath, 'w') do |f|
f.write file.read
end
save!
end
end