]> source.dussan.org Git - redmine.git/commitdiff
code cleanup: rubocop: fix Lint/IneffectiveAccessModifier in app/models/mail_handler.rb
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 19 Oct 2019 13:34:05 +0000 (13:34 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sat, 19 Oct 2019 13:34:05 +0000 (13:34 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@18782 e93f8b46-1217-0410-a6f0-8f06a7374b81

.rubocop_todo.yml
app/models/mail_handler.rb

index 519f17fe2afc1cd6bb671f6f3355de6410fb1f91..a782c472c690405eee1c3a3e474d1c5ecbfcc634 100644 (file)
@@ -388,10 +388,6 @@ Lint/HandleExceptions:
     - 'lib/redmine/scm/adapters/cvs_adapter.rb'
     - 'lib/redmine/scm/adapters/subversion_adapter.rb'
 
-Lint/IneffectiveAccessModifier:
-  Exclude:
-    - 'app/models/mail_handler.rb'
-
 Lint/InterpolationCheck:
   Exclude:
     - 'app/models/user.rb'
index 3e7b02b90e033500b6694ceb459cca409c2ca045..7f03591e274c1eac20a5335c3895eb16c50dec6e 100644 (file)
@@ -523,18 +523,6 @@ class MailHandler < ActionMailer::Base
     subject.strip[0,255]
   end
 
-  # Converts a HTML email body to text
-  def self.html_body_to_text(html)
-    Redmine::WikiFormatting.html_parser.to_text(html)
-  end
-
-  # Converts a plain/text email body to text
-  def self.plain_text_body_to_text(text)
-    # Removes leading spaces that would cause the line to be rendered as
-    # preformatted text with textile
-    text.gsub(/^ +(?![*#])/, '')
-  end
-
   def self.assign_string_attribute_with_limit(object, attribute, value, limit=nil)
     limit ||= object.class.columns_hash[attribute.to_s].limit || 255
     value = value.to_s.slice(0, limit)
@@ -542,29 +530,43 @@ class MailHandler < ActionMailer::Base
   end
   private_class_method :assign_string_attribute_with_limit
 
-  # Returns a User from an email address and a full name
-  def self.new_user_from_attributes(email_address, fullname=nil)
-    user = User.new
+  # Singleton class method is public
+  class << self
+    # Converts a HTML email body to text
+    def html_body_to_text(html)
+      Redmine::WikiFormatting.html_parser.to_text(html)
+    end
+
+    # Converts a plain/text email body to text
+    def plain_text_body_to_text(text)
+      # Removes leading spaces that would cause the line to be rendered as
+      # preformatted text with textile
+      text.gsub(/^ +(?![*#])/, '')
+    end
 
-    # Truncating the email address would result in an invalid format
-    user.mail = email_address
-    assign_string_attribute_with_limit(user, 'login', email_address, User::LOGIN_LENGTH_LIMIT)
+    # Returns a User from an email address and a full name
+    def new_user_from_attributes(email_address, fullname=nil)
+      user = User.new
 
-    names = fullname.blank? ? email_address.gsub(/@.*$/, '').split('.') : fullname.split
-    assign_string_attribute_with_limit(user, 'firstname', names.shift, 30)
-    assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30)
-    user.lastname = '-' if user.lastname.blank?
-    user.language = Setting.default_language
-    user.generate_password = true
-    user.mail_notification = 'only_my_events'
+      # Truncating the email address would result in an invalid format
+      user.mail = email_address
+      assign_string_attribute_with_limit(user, 'login', email_address, User::LOGIN_LENGTH_LIMIT)
 
-    unless user.valid?
-      user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank?
-      user.firstname = "-" unless user.errors[:firstname].blank?
-      (puts user.errors[:lastname]; user.lastname  = "-") unless user.errors[:lastname].blank?
-    end
+      names = fullname.blank? ? email_address.gsub(/@.*$/, '').split('.') : fullname.split
+      assign_string_attribute_with_limit(user, 'firstname', names.shift, 30)
+      assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30)
+      user.lastname = '-' if user.lastname.blank?
+      user.language = Setting.default_language
+      user.generate_password = true
+      user.mail_notification = 'only_my_events'
 
-    user
+      unless user.valid?
+        user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank?
+        user.firstname = "-" unless user.errors[:firstname].blank?
+        (puts user.errors[:lastname]; user.lastname  = "-") unless user.errors[:lastname].blank?
+      end
+      user
+    end
   end
 
   # Creates a User for the +email+ sender