annotate app/models/paste.rb @ 66:e0817b84c01b

Allow post in txt format.
author Edho Arief <edho@myconan.net>
date Thu, 04 Oct 2012 10:20:19 +0700
parents 36d07f047ec2
children 8f0fb869e770
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
1 class Paste < ActiveRecord::Base
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
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
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
4 before_validation :set_paste_hash
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
5 validates :paste, :paste_hash, :ip, :presence => true
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
6 validates :paste, :length => { :maximum => 1_000_000 }
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
7
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
8 def set_paste_hash
51
36d07f047ec2 Or maybe not. Still too long with b62. Backed out changeset ba29d6394863
Edho Arief <edho@myconan.net>
parents: 46
diff changeset
9 self.paste_hash = Digest::SHA512.hexdigest("#{paste}\n")
2
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
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
42de15334db1 Added the pastes.
Edho Arief <edho@myconan.net>
parents:
diff changeset
21 end