comparison app/models/paste.rb @ 379:2ad092e60975

[mq]: new-design
author nanaya <me@myconan.net>
date Sun, 07 Jun 2015 02:35:12 +0900
parents 4e6afc8140fb
children 9369ad2f2ce8
comparison
equal deleted inserted replaced
378:e84276bf344a 379:2ad092e60975
1 class Paste < ActiveRecord::Base 1 class Paste < ActiveRecord::Base
2 attr_accessor :is_private 2 attr_accessor :is_private
3 after_initialize :set_privacy, :if => :new_record?
4
3 before_validation :paste_limit 5 before_validation :paste_limit
4 before_validation :convert_newlines 6 before_validation :convert_newlines
5 before_validation :set_paste_hash 7 before_validation :set_paste_hash
6 before_validation :set_paste_key 8 before_validation :set_paste_key
7 before_validation :set_paste_secret 9 before_validation :set_paste_secret
81 def paste_limit 83 def paste_limit
82 ip_post_recent_count = self.class.where(:ip => ip).where("created_at > ?", Time.zone.now - 1.hour).count 84 ip_post_recent_count = self.class.where(:ip => ip).where("created_at > ?", Time.zone.now - 1.hour).count
83 errors.add :base, :limit if ip_post_recent_count > 100 85 errors.add :base, :limit if ip_post_recent_count > 100
84 end 86 end
85 87
88 def set_privacy
89 self.is_private ||= "0"
90 end
91
86 def self.fix_all 92 def self.fix_all
87 stats = Hash.new(0) 93 stats = Hash.new(0)
88 all.find_each do |p| 94 all.find_each do |p|
89 p.save 95 p.save
90 stats[:count] += 1 96 stats[:count] += 1