Mercurial > zeropaste
comparison app/models/paste.rb @ 376:02903dc8214d
Fix code styles.
- remove return and self keyword and use find_each instead of each.
author | nanaya <me@myconan.net> |
---|---|
date | Sat, 06 Jun 2015 22:34:36 +0900 |
parents | 6e3e1e7b0212 |
children | 4e6afc8140fb |
comparison
equal
deleted
inserted
replaced
375:66ee2f5e793e | 376:02903dc8214d |
---|---|
21 nil | 21 nil |
22 end | 22 end |
23 end | 23 end |
24 | 24 |
25 def self.graceful_create(params) | 25 def self.graceful_create(params) |
26 paste = self.new(params) | 26 paste = new(params) |
27 fresh = true | 27 fresh = true |
28 created = true | 28 created = true |
29 | 29 |
30 begin | 30 begin |
31 created = paste.save | 31 created = paste.save |
32 rescue ActiveRecord::RecordNotUnique | 32 rescue ActiveRecord::RecordNotUnique |
33 paste = self.find_by(:ip => paste.ip, :paste_hash => paste.paste_hash) | 33 paste = find_by(:ip => paste.ip, :paste_hash => paste.paste_hash) |
34 fresh = false | 34 fresh = false |
35 end | 35 end |
36 | 36 |
37 return [created, paste, fresh] | 37 [created, paste, fresh] |
38 end | 38 end |
39 | 39 |
40 def paste_gzip=(paste) | 40 def paste_gzip=(paste) |
41 self.paste = ActiveSupport::Gzip.decompress paste | 41 self.paste = ActiveSupport::Gzip.decompress paste |
42 end | 42 end |
83 errors.add :base, :limit if ip_post_recent_count > 100 | 83 errors.add :base, :limit if ip_post_recent_count > 100 |
84 end | 84 end |
85 | 85 |
86 def self.fix_all | 86 def self.fix_all |
87 stats = Hash.new(0) | 87 stats = Hash.new(0) |
88 all.each do |p| | 88 all.find_each do |p| |
89 p.save | 89 p.save |
90 stats[:count] += 1 | 90 stats[:count] += 1 |
91 stats[:private] += 1 if p.secret | 91 stats[:private] += 1 if p.secret |
92 end | 92 end |
93 stats | 93 stats |