Avoid using to_s when performing String Interpolation

This commit is contained in:
Akshay 2014-08-14 23:50:52 +05:30
parent 5d9a389966
commit 7ef61144e7
18 changed files with 26 additions and 26 deletions

View file

@ -13,7 +13,7 @@ class ForumsController < ApplicationController
end
def error
raise "WAT - #{Time.now.to_s}"
raise "WAT - #{Time.now}"
end
def home_redirect

View file

@ -83,7 +83,7 @@ class Post < ActiveRecord::Base
def limit_posts_per_day
if user.created_at > 1.day.ago && post_number > 1
RateLimiter.new(user, "first-day-replies-per-day:#{Date.today.to_s}", SiteSetting.max_replies_in_first_day, 1.day.to_i)
RateLimiter.new(user, "first-day-replies-per-day:#{Date.today}", SiteSetting.max_replies_in_first_day, 1.day.to_i)
end
end

View file

@ -282,7 +282,7 @@ class PostAction < ActiveRecord::Base
%w(like flag bookmark).each do |type|
if send("is_#{type}?")
@rate_limiter = RateLimiter.new(user, "create_#{type}:#{Date.today.to_s}", SiteSetting.send("max_#{type}s_per_day"), 1.day.to_i)
@rate_limiter = RateLimiter.new(user, "create_#{type}:#{Date.today}", SiteSetting.send("max_#{type}s_per_day"), 1.day.to_i)
return @rate_limiter
end
end
@ -330,7 +330,7 @@ class PostAction < ActiveRecord::Base
def update_counters
# Update denormalized counts
column = "#{post_action_type_key.to_s}_count"
column = "#{post_action_type_key}_count"
count = PostAction.where(post_id: post_id)
.where(post_action_type_id: post_action_type_id)
.count

View file

@ -105,7 +105,7 @@ class PostMover
def create_moderator_post_in_original_topic
original_topic.add_moderator_post(
user,
I18n.t("move_posts.#{PostMover.move_types[@move_type].to_s}_moderator_post",
I18n.t("move_posts.#{PostMover.move_types[@move_type]}_moderator_post",
count: post_ids.count,
topic_link: "[#{destination_topic.title}](#{destination_topic.url})"),
post_number: @first_post_number_moved

View file

@ -51,7 +51,7 @@ class ScreenedIpAddress < ActiveRecord::Base
if mask == 32
ip_address.to_s
else
"#{ip_address.to_s}/#{ip_address.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
"#{ip_address}/#{ip_address.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
end
else
nil

View file

@ -142,7 +142,7 @@ class Topic < ActiveRecord::Base
# Helps us limit how many topics can be starred in a day
class StarLimiter < RateLimiter
def initialize(user)
super(user, "starred:#{Date.today.to_s}", SiteSetting.max_stars_per_day, 1.day.to_i)
super(user, "starred:#{Date.today}", SiteSetting.max_stars_per_day, 1.day.to_i)
end
end
@ -834,7 +834,7 @@ class Topic < ActiveRecord::Base
end
def apply_per_day_rate_limit_for(key, method_name)
RateLimiter.new(user, "#{key}-per-day:#{Date.today.to_s}", SiteSetting.send(method_name), 1.day.to_i)
RateLimiter.new(user, "#{key}-per-day:#{Date.today}", SiteSetting.send(method_name), 1.day.to_i)
end
end

View file

@ -8,7 +8,7 @@ class TopicViewItem < ActiveRecord::Base
def self.add(topic_id, ip, user_id=nil, at=nil, skip_redis=false)
# Only store a view once per day per thing per user per ip
redis_key = "view:#{topic_id}:#{Date.today.to_s}"
redis_key = "view:#{topic_id}:#{Date.today}"
if user_id
redis_key << ":user-#{user_id}"
else

View file

@ -57,7 +57,7 @@ class UserHistory < ActiveRecord::Base
end
[:acting_user, :target_user].each do |key|
if filters[key] and obj_id = User.where(username_lower: filters[key].downcase).pluck(:id)
query = query.where("#{key.to_s}_id = ?", obj_id)
query = query.where("#{key}_id = ?", obj_id)
end
end
query = query.where("subject = ?", filters[:subject]) if filters[:subject]

View file

@ -58,12 +58,12 @@ class UserUpdater
USER_ATTR.each do |attribute|
if attributes[attribute].present?
user.send("#{attribute.to_s}=", attributes[attribute] == 'true')
user.send("#{attribute}=", attributes[attribute] == 'true')
end
end
PROFILE_ATTR.each do |attribute|
user_profile.send("#{attribute.to_s}=", attributes[attribute])
user_profile.send("#{attribute}=", attributes[attribute])
end
if fields = attributes[:custom_fields]

View file

@ -45,8 +45,8 @@ action :enable do
# handler code. TODO: add a :reload action
converge_by("enable #{@new_resource} as a #{type} handler") do
Chef::Log.info("Enabling #{@new_resource} as a #{type} handler")
Chef::Config.send("#{type.to_s}_handlers").delete_if { |v| v.class.to_s.include? @new_resource.class_name.split('::', 3).last }
Chef::Config.send("#{type.to_s}_handlers") << handler
Chef::Config.send("#{type}_handlers").delete_if { |v| v.class.to_s.include? @new_resource.class_name.split('::', 3).last }
Chef::Config.send("#{type}_handlers") << handler
end
end
end
@ -57,7 +57,7 @@ action :disable do
if enabled?(type)
converge_by("disable #{@new_resource} as a #{type} handler") do
Chef::Log.info("Disabling #{@new_resource} as a #{type} handler")
Chef::Config.send("#{type.to_s}_handlers").delete_if { |v| v.class.to_s.include? @new_resource.class_name.split('::', 3).last }
Chef::Config.send("#{type}_handlers").delete_if { |v| v.class.to_s.include? @new_resource.class_name.split('::', 3).last }
end
end
end
@ -73,7 +73,7 @@ end
private
def enabled?(type)
Chef::Config.send("#{type.to_s}_handlers").select do |handler|
Chef::Config.send("#{type}_handlers").select do |handler|
handler.class.to_s.include? @new_resource.class_name
end.size >= 1
end

View file

@ -24,15 +24,15 @@ class Chef
end
def install_feature(name)
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :install"
raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :install"
end
def remove_feature(name)
raise Chef::Exceptions::UnsupportedAction, "#{self.to_s} does not support :remove"
raise Chef::Exceptions::UnsupportedAction, "#{self} does not support :remove"
end
def installed?
raise Chef::Exceptions::Override, "You must override installed? in #{self.to_s}"
raise Chef::Exceptions::Override, "You must override installed? in #{self}"
end
end
end

View file

@ -1,6 +1,6 @@
require 'rate_limiter'
class EditRateLimiter < RateLimiter
def initialize(user)
super(user, "edit-post:#{Date.today.to_s}", SiteSetting.max_edits_per_day, 1.day.to_i)
super(user, "edit-post:#{Date.today}", SiteSetting.max_edits_per_day, 1.day.to_i)
end
end

View file

@ -62,7 +62,7 @@ module FileStore
private
def get_path_for_upload(file, upload)
unique_sha1 = Digest::SHA1.hexdigest("#{Time.now.to_s}#{upload.original_filename}")[0..15]
unique_sha1 = Digest::SHA1.hexdigest("#{Time.now}#{upload.original_filename}")[0..15]
extension = File.extname(upload.original_filename)
clean_name = "#{unique_sha1}#{extension}"
# path

View file

@ -19,7 +19,7 @@ class Promotion
trust_key = TrustLevel.levels[@user.trust_level]
review_method = :"review_#{trust_key.to_s}"
review_method = :"review_#{trust_key}"
return send(review_method) if respond_to?(review_method)
false

View file

@ -33,7 +33,7 @@ class ScoreCalculator
def update_posts_score(min_topic_age)
components = []
@weightings.keys.each { |k| components << "COALESCE(#{k.to_s}, 0) * :#{k.to_s}" }
@weightings.keys.each { |k| components << "COALESCE(#{k}, 0) * :#{k}" }
components = components.join(" + ")
builder = SqlBuilder.new(

View file

@ -22,7 +22,7 @@ class Search
def as_json(options = nil)
{ type: @type.to_s,
name: I18n.t("search.types.#{@type.to_s}"),
name: I18n.t("search.types.#{@type}"),
more: @more,
results: @results.map(&:as_json) }
end

View file

@ -102,7 +102,7 @@ class Typepad < Thor
ensure
RateLimiter.enable
backup_settings.each do |s, v|
SiteSetting.send("#{s.to_s}=", v)
SiteSetting.send("#{s}=", v)
end
end

View file

@ -3,6 +3,6 @@ RSpec::Matchers.define :be_within_one_second_of do |expected_time|
(actual_time - expected_time).abs < 1
end
failure_message_for_should do |actual_time|
"#{actual_time.to_s} is not within 1 second of #{expected_time}"
"#{actual_time} is not within 1 second of #{expected_time}"
end
end