From 7ef61144e781f4fd9e17dff0163449498774dd5f Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 14 Aug 2014 23:50:52 +0530 Subject: [PATCH] Avoid using to_s when performing String Interpolation --- app/controllers/forums_controller.rb | 2 +- app/models/post.rb | 2 +- app/models/post_action.rb | 4 ++-- app/models/post_mover.rb | 2 +- app/models/screened_ip_address.rb | 2 +- app/models/topic.rb | 4 ++-- app/models/topic_view_item.rb | 2 +- app/models/user_history.rb | 2 +- app/services/user_updater.rb | 4 ++-- chef/cookbooks/chef_handler/providers/default.rb | 8 ++++---- chef/cookbooks/windows/libraries/feature_base.rb | 6 +++--- lib/edit_rate_limiter.rb | 2 +- lib/file_store/local_store.rb | 2 +- lib/promotion.rb | 2 +- lib/score_calculator.rb | 2 +- lib/search/search_result_type.rb | 2 +- lib/tasks/typepad.thor | 2 +- spec/support/time_matcher.rb | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 32f7f9b2c..d930c0da9 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -13,7 +13,7 @@ class ForumsController < ApplicationController end def error - raise "WAT - #{Time.now.to_s}" + raise "WAT - #{Time.now}" end def home_redirect diff --git a/app/models/post.rb b/app/models/post.rb index 60678011f..d7514d368 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 016a0d11f..fb0e33eb3 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -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 diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 2fe745087..5b156785b 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -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 diff --git a/app/models/screened_ip_address.rb b/app/models/screened_ip_address.rb index 4787673eb..876e7a2f5 100644 --- a/app/models/screened_ip_address.rb +++ b/app/models/screened_ip_address.rb @@ -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 diff --git a/app/models/topic.rb b/app/models/topic.rb index 3d0ca4bb5..e0fb6736b 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -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 diff --git a/app/models/topic_view_item.rb b/app/models/topic_view_item.rb index ecb659cc6..6f5ca40c3 100644 --- a/app/models/topic_view_item.rb +++ b/app/models/topic_view_item.rb @@ -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 diff --git a/app/models/user_history.rb b/app/models/user_history.rb index 7b57eddc0..0ea46b324 100644 --- a/app/models/user_history.rb +++ b/app/models/user_history.rb @@ -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] diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index dce86dccf..214e8a6c3 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -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] diff --git a/chef/cookbooks/chef_handler/providers/default.rb b/chef/cookbooks/chef_handler/providers/default.rb index 2eb2be73a..49d60595e 100644 --- a/chef/cookbooks/chef_handler/providers/default.rb +++ b/chef/cookbooks/chef_handler/providers/default.rb @@ -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 diff --git a/chef/cookbooks/windows/libraries/feature_base.rb b/chef/cookbooks/windows/libraries/feature_base.rb index 66cbc42de..aa92b93d1 100644 --- a/chef/cookbooks/windows/libraries/feature_base.rb +++ b/chef/cookbooks/windows/libraries/feature_base.rb @@ -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 diff --git a/lib/edit_rate_limiter.rb b/lib/edit_rate_limiter.rb index f91291eda..3c42a89bf 100644 --- a/lib/edit_rate_limiter.rb +++ b/lib/edit_rate_limiter.rb @@ -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 diff --git a/lib/file_store/local_store.rb b/lib/file_store/local_store.rb index 528ea4b7b..7ebd95689 100644 --- a/lib/file_store/local_store.rb +++ b/lib/file_store/local_store.rb @@ -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 diff --git a/lib/promotion.rb b/lib/promotion.rb index 88f1c2671..60d60f1db 100644 --- a/lib/promotion.rb +++ b/lib/promotion.rb @@ -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 diff --git a/lib/score_calculator.rb b/lib/score_calculator.rb index 6f11ec291..343edbe5b 100644 --- a/lib/score_calculator.rb +++ b/lib/score_calculator.rb @@ -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( diff --git a/lib/search/search_result_type.rb b/lib/search/search_result_type.rb index 1baa9f155..85c9038a2 100644 --- a/lib/search/search_result_type.rb +++ b/lib/search/search_result_type.rb @@ -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 diff --git a/lib/tasks/typepad.thor b/lib/tasks/typepad.thor index 016c2b084..26613f89b 100644 --- a/lib/tasks/typepad.thor +++ b/lib/tasks/typepad.thor @@ -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 diff --git a/spec/support/time_matcher.rb b/spec/support/time_matcher.rb index f50f9c1f8..6fe445a62 100644 --- a/spec/support/time_matcher.rb +++ b/spec/support/time_matcher.rb @@ -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 \ No newline at end of file