comparison app/models/paste.rb @ 330:96631607785f

Even more coding style.
author edogawaconan <me@myconan.net>
date Mon, 14 Apr 2014 17:17:32 +0900
parents 61f7f258a6fb
children 6e3e1e7b0212
comparison
equal deleted inserted replaced
329:430dadffd91e 330:96631607785f
14 14
15 def self.safe_find(raw_id) 15 def self.safe_find(raw_id)
16 id, secret = raw_id.to_s.split("-") 16 id, secret = raw_id.to_s.split("-")
17 return unless id.to_i.to_s == id 17 return unless id.to_i.to_s == id
18 begin 18 begin
19 self.where(:secret => secret).find(id) 19 where(:secret => secret).find(id)
20 rescue ActiveRecord::RecordNotFound 20 rescue ActiveRecord::RecordNotFound
21 nil 21 nil
22 end 22 end
23 end 23 end
24 24
50 def set_paste_key 50 def set_paste_key
51 self.key ||= SecureRandom.hex(4) 51 self.key ||= SecureRandom.hex(4)
52 end 52 end
53 53
54 def set_paste_secret 54 def set_paste_secret
55 self.secret = SecureRandom.hex(4) if self.is_private? 55 self.secret = SecureRandom.hex(4) if is_private?
56 end 56 end
57 57
58 def is_private? 58 def is_private?
59 self.is_private == "1" 59 is_private == "1"
60 end 60 end
61 61
62 def convert_newlines 62 def convert_newlines
63 self.paste = self.paste.to_s.gsub("\r\n", "\n").gsub("\r", "\n") 63 self.paste = paste.to_s.gsub("\r\n", "\n").gsub("\r", "\n")
64 end 64 end
65 65
66 def paste_limit 66 def paste_limit
67 ip_post_recent_count = self.class.where(:ip => self.ip).where('created_at > ?', Time.now - 1.hour).count 67 ip_post_recent_count = self.class.where(:ip => ip).where("created_at > ?", Time.now - 1.hour).count
68 errors.add :base, :limit if ip_post_recent_count > 100 68 errors.add :base, :limit if ip_post_recent_count > 100
69 end 69 end
70 70
71 def self.fix_all 71 def self.fix_all
72 stats = Hash.new(0) 72 stats = Hash.new(0)
73 self.all.each do |p| 73 all.each do |p|
74 p.save 74 p.save
75 stats[:count] += 1 75 stats[:count] += 1
76 stats[:private] += 1 if p.secret 76 stats[:private] += 1 if p.secret
77 end 77 end
78 return stats 78 stats
79 end 79 end
80 end 80 end