Mercurial > zeropaste
annotate app/models/paste.rb @ 35:e09a3be8dd14
Hardcoded rows.
author | Edho Arief <edho@myconan.net> |
---|---|
date | Mon, 10 Sep 2012 15:21:25 +0700 |
parents | a8cdf1f45446 |
children | ba29d6394863 |
rev | line source |
---|---|
2 | 1 class Paste < ActiveRecord::Base |
2 attr_accessible :paste | |
22
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
3 before_validation :convert_newlines |
2 | 4 before_validation :set_paste_hash |
5 validates :paste, :paste_hash, :ip, :presence => true | |
6 validates :paste, :length => { :maximum => 1_000_000 } | |
7 | |
8 def set_paste_hash | |
24
a8cdf1f45446
Add newline/eol before hashing the paste.
Edho Arief <edho@myconan.net>
parents:
22
diff
changeset
|
9 self.paste_hash = Digest::SHA512.hexdigest("#{paste}\n") |
2 | 10 end |
22
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
11 |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
12 def convert_newlines |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
13 self.paste = self.paste.gsub("\r\n", "\n").gsub("\r", "\n") |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
14 end |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
15 |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
16 def self.fix_all |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
17 self.all.each do |p| |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
18 p.save |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
19 end |
032686a0c995
Added newline converter, integrity fixups.
Edho Arief <edho@myconan.net>
parents:
2
diff
changeset
|
20 end |
2 | 21 end |