comparison app/models/paste.rb @ 22:032686a0c995

Added newline converter, integrity fixups.
author Edho Arief <edho@myconan.net>
date Wed, 05 Sep 2012 14:36:10 +0700
parents 42de15334db1
children a8cdf1f45446
comparison
equal deleted inserted replaced
21:3c31c0beb9c2 22:032686a0c995
1 class Paste < ActiveRecord::Base 1 class Paste < ActiveRecord::Base
2 attr_accessible :paste 2 attr_accessible :paste
3 before_validation :convert_newlines
3 before_validation :set_paste_hash 4 before_validation :set_paste_hash
4 validates :paste, :paste_hash, :ip, :presence => true 5 validates :paste, :paste_hash, :ip, :presence => true
5 validates :paste, :length => { :maximum => 1_000_000 } 6 validates :paste, :length => { :maximum => 1_000_000 }
6 7
7 def set_paste_hash 8 def set_paste_hash
8 self.paste_hash = Digest::SHA512.hexdigest(paste) 9 self.paste_hash = Digest::SHA512.hexdigest(paste)
9 end 10 end
11
12 def convert_newlines
13 self.paste = self.paste.gsub("\r\n", "\n").gsub("\r", "\n")
14 end
15
16 def self.fix_all
17 self.all.each do |p|
18 p.save
19 end
20 end
10 end 21 end