comparison app/models/paste.rb @ 431:68eb23b52864

Rails 5 \o/
author nanaya <me@myconan.net>
date Fri, 13 May 2016 03:56:07 +0900
parents 9fc6b919369c
children b445318de858
comparison
equal deleted inserted replaced
430:6257da6e1aa1 431:68eb23b52864
15 end 15 end
16 16
17 def self.safe_find(raw_id) 17 def self.safe_find(raw_id)
18 /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/ =~ raw_id.to_s 18 /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/ =~ raw_id.to_s
19 19
20 where(:secret => secret, :id => id).take 20 find_by(:secret => secret, :id => id)
21 end 21 end
22 22
23 def self.graceful_create(params) 23 def self.graceful_create(params)
24 paste = new(params) 24 paste = new(params)
25 fresh = true 25 fresh = true
71 def is_private? 71 def is_private?
72 is_private == "1" 72 is_private == "1"
73 end 73 end
74 74
75 def convert_newlines 75 def convert_newlines
76 self.paste = paste.to_s.gsub("\r\n", "\n").gsub("\r", "\n") 76 self.paste = paste.to_s.gsub("\r\n", "\n").tr("\r", "\n")
77 end 77 end
78 78
79 def paste_limit 79 def paste_limit
80 ip_post_recent_count = self.class.where(:ip => ip).where("created_at > ?", Time.zone.now - 1.hour).count 80 ip_post_recent_count = self.class.where(:ip => ip).where("created_at > ?", Time.zone.now - 1.hour).count
81 errors.add :base, :limit if ip_post_recent_count > 100 81 errors.add :base, :limit if ip_post_recent_count > 100