From 9524b514c6bcd31d23b75fcd08f9928166fcfd12 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 4 Oct 2014 08:37:20 +0530 Subject: [PATCH 1/2] Fix access specifiers with private_class_methods instead of removing directly --- app/models/admin_dashboard_data.rb | 1 + app/models/category_user.rb | 1 + app/models/email_log.rb | 5 ++--- app/models/email_token.rb | 4 +--- app/models/error_log.rb | 1 + app/models/global_setting.rb | 2 ++ app/models/locale_site_setting.rb | 2 ++ app/models/s3_region_site_setting.rb | 2 ++ app/models/top_topic.rb | 3 +++ app/models/trust_level_setting.rb | 2 ++ 10 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb index c74fbe0d6e0..83124e174f1 100644 --- a/app/models/admin_dashboard_data.rb +++ b/app/models/admin_dashboard_data.rb @@ -203,4 +203,5 @@ class AdminDashboardData 'dash-data:access_password_removal' end + private_class_method :access_password_removal_key end diff --git a/app/models/category_user.rb b/app/models/category_user.rb index 1b65dccfb10..4ba4a130d14 100644 --- a/app/models/category_user.rb +++ b/app/models/category_user.rb @@ -81,6 +81,7 @@ SQL ) end + private_class_method :apply_default_to_topic end # == Schema Information diff --git a/app/models/email_log.rb b/app/models/email_log.rb index 08a9e9615a4..a9b94c8cf1a 100644 --- a/app/models/email_log.rb +++ b/app/models/email_log.rb @@ -1,11 +1,10 @@ class EmailLog < ActiveRecord::Base belongs_to :user - validates_presence_of :email_type - validates_presence_of :to_address - belongs_to :post belongs_to :topic + validates :email_type, :to_address, presence: true + scope :sent, -> { where(skipped: false) } scope :skipped, -> { where(skipped: true) } diff --git a/app/models/email_token.rb b/app/models/email_token.rb index d98ed4326ff..8a08f3f514c 100644 --- a/app/models/email_token.rb +++ b/app/models/email_token.rb @@ -1,9 +1,7 @@ class EmailToken < ActiveRecord::Base belongs_to :user - validates_presence_of :token - validates_presence_of :user_id - validates_presence_of :email + validates :token, :user_id, :email, presence: true before_validation(on: :create) do self.token = EmailToken.generate_token diff --git a/app/models/error_log.rb b/app/models/error_log.rb index b1dd90eec49..8c7944e8625 100644 --- a/app/models/error_log.rb +++ b/app/models/error_log.rb @@ -90,4 +90,5 @@ class ErrorLog trace.map { |line| Pathname.new(line.gsub(re, "[RAILS_ROOT]")).cleanpath.to_s } end + private_class_method :sanitize_backtrace end diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb index cea2ca92b65..1d89a031224 100644 --- a/app/models/global_setting.rb +++ b/app/models/global_setting.rb @@ -85,6 +85,8 @@ class GlobalSetting provider.read provider end + + private_class_method :parse end class EnvProvider < BaseProvider diff --git a/app/models/locale_site_setting.rb b/app/models/locale_site_setting.rb index 5c73595651b..8cf30de532b 100644 --- a/app/models/locale_site_setting.rb +++ b/app/models/locale_site_setting.rb @@ -19,4 +19,6 @@ class LocaleSiteSetting < EnumSiteSetting @supported_locales ||= Dir.glob( File.join(Rails.root, 'config', 'locales', 'client.*.yml') ).map {|x| x.split('.')[-2]}.sort end end + + private_class_method :supported_locales end diff --git a/app/models/s3_region_site_setting.rb b/app/models/s3_region_site_setting.rb index 9b2ec0ce81c..decefb185e7 100644 --- a/app/models/s3_region_site_setting.rb +++ b/app/models/s3_region_site_setting.rb @@ -21,4 +21,6 @@ class S3RegionSiteSetting < EnumSiteSetting 'ap-northeast-1', 'sa-east-1'] end + + private_class_method :valid_values end diff --git a/app/models/top_topic.rb b/app/models/top_topic.rb index a891dda3955..d9253ae74eb 100644 --- a/app/models/top_topic.rb +++ b/app/models/top_topic.rb @@ -154,6 +154,9 @@ class TopTopic < ActiveRecord::Base from: start_of(period)) end + private_class_method :sort_orders, :update_counts_and_compute_scores_for, :remove_invisible_topics, + :add_new_visible_topics, :update_posts_count_for, :update_views_count_for, :update_likes_count_for, + :compute_top_score_for, :start_of, :update_top_topics end # == Schema Information diff --git a/app/models/trust_level_setting.rb b/app/models/trust_level_setting.rb index a2d91ba8c89..e76f258280a 100644 --- a/app/models/trust_level_setting.rb +++ b/app/models/trust_level_setting.rb @@ -13,4 +13,6 @@ class TrustLevelSetting < EnumSiteSetting def self.valid_values TrustLevel.valid_range.to_a end + + private_class_method :valid_values end From 378bc6e5dc34da9b7e7a94355abe2a9a8ff1ec56 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 4 Oct 2014 09:53:46 +0530 Subject: [PATCH 2/2] private methods need to be called as method_name instead of ClassName#method_name --- app/models/top_topic.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/top_topic.rb b/app/models/top_topic.rb index d9253ae74eb..cad2eebc97a 100644 --- a/app/models/top_topic.rb +++ b/app/models/top_topic.rb @@ -14,7 +14,7 @@ class TopTopic < ActiveRecord::Base # We don't have to refresh these as often def self.refresh_older! - older_periods = TopTopic.periods - [:daily] + older_periods = periods - [:daily] transaction do older_periods.each do |period| @@ -24,8 +24,8 @@ class TopTopic < ActiveRecord::Base end def self.refresh! - TopTopic.refresh_daily! - TopTopic.refresh_older! + refresh_daily! + refresh_older! end @@ -38,10 +38,10 @@ class TopTopic < ActiveRecord::Base end def self.update_counts_and_compute_scores_for(period) - TopTopic.sort_orders.each do |sort| + sort_orders.each do |sort| TopTopic.send("update_#{sort}_count_for", period) end - TopTopic.compute_top_score_for(period) + compute_top_score_for(period) end def self.remove_invisible_topics @@ -90,7 +90,7 @@ class TopTopic < ActiveRecord::Base AND user_id <> #{Discourse.system_user.id} GROUP BY topic_id" - TopTopic.update_top_topics(period, "posts", sql) + update_top_topics(period, "posts", sql) end def self.update_views_count_for(period) @@ -99,7 +99,7 @@ class TopTopic < ActiveRecord::Base WHERE viewed_at >= :from GROUP BY topic_id" - TopTopic.update_top_topics(period, "views", sql) + update_top_topics(period, "views", sql) end def self.update_likes_count_for(period) @@ -111,7 +111,7 @@ class TopTopic < ActiveRecord::Base AND post_type = #{Post.types[:regular]} GROUP BY topic_id" - TopTopic.update_top_topics(period, "likes", sql) + update_top_topics(period, "likes", sql) end def self.compute_top_score_for(period)