diff app/models/paste.rb @ 499:d2ef59c9a4b4

Use rails rubocop
author nanaya <me@nanaya.net>
date Sun, 15 Dec 2024 22:33:27 +0900
parents 84ca55a0568e
children
line wrap: on
line diff
--- a/app/models/paste.rb	Sun Dec 15 22:31:14 2024 +0900
+++ b/app/models/paste.rb	Sun Dec 15 22:33:27 2024 +0900
@@ -1,14 +1,14 @@
 class Paste < ApplicationRecord
   attr_accessor :is_private
-  after_initialize :set_privacy, :if => :new_record?
+  after_initialize :set_privacy, if: :new_record?
 
   before_validation :paste_limit
   before_validation :convert_newlines
   before_validation :set_paste_hash
   before_validation :set_paste_key
   before_validation :set_paste_secret
-  validates :paste, :paste_hash, :key, :ip, :presence => true
-  validates :paste, :length => { :maximum => 1_000_000 }
+  validates :paste, :paste_hash, :key, :ip, presence: true
+  validates :paste, length: { maximum: 1_000_000 }
 
   def to_param
     path
@@ -17,7 +17,7 @@
   def self.safe_find(raw_id)
     /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/i =~ raw_id.to_s
 
-    find_by(:secret => secret.try(:downcase), :id => id)
+    find_by(secret: secret.try(:downcase), id: id)
   end
 
   def self.graceful_create(params)
@@ -28,11 +28,11 @@
     begin
       created = paste.save
     rescue ActiveRecord::RecordNotUnique
-      paste = find_by(:ip => paste.ip, :paste_hash => paste.paste_hash)
+      paste = find_by(ip: paste.ip, paste_hash: paste.paste_hash)
       fresh = false
     end
 
-    [created, paste, fresh]
+    [ created, paste, fresh ]
   end
 
   def paste_gzip=(paste)
@@ -55,7 +55,7 @@
   end
 
   def path
-    [id, secret.presence].compact.join("-")
+    [ id, secret.presence ].compact.join("-")
   end
 
   def set_paste_hash
@@ -79,7 +79,7 @@
   end
 
   def paste_limit
-    ip_post_recent_count = self.class.where(:ip => ip).where("created_at > ?", Time.zone.now - 1.hour).count
+    ip_post_recent_count = self.class.where(ip: ip).where("created_at > ?", Time.zone.now - 1.hour).count
     errors.add :base, :limit if ip_post_recent_count > 100
   end