Browse Source

Class methods, colon method call

Maarten van den Berg 6 years ago
parent
commit
1a877f7a67
4 changed files with 6 additions and 19 deletions
  1. 0 13
      .rubocop.yml
  2. 3 3
      app/controllers/authentication_controller.rb
  3. 2 2
      app/models/session.rb
  4. 1 1
      app/models/token.rb

+ 0 - 13
.rubocop.yml

45
 Metrics/PerceivedComplexity:
45
 Metrics/PerceivedComplexity:
46
   Max: 13
46
   Max: 13
47
 
47
 
48
-# Offense count: 2
49
-# Cop supports --auto-correct.
50
-Style/ClassMethods:
51
-  Exclude:
52
-    - 'app/models/session.rb'
53
-
54
-# Offense count: 4
55
-# Cop supports --auto-correct.
56
-Style/ColonMethodCall:
57
-  Exclude:
58
-    - 'app/controllers/authentication_controller.rb'
59
-    - 'app/models/token.rb'
60
-
61
 # Offense count: 55
48
 # Offense count: 55
62
 Style/Documentation:
49
 Style/Documentation:
63
   Enabled: false
50
   Enabled: false

+ 3 - 3
app/controllers/authentication_controller.rb

63
       user = User.new
63
       user = User.new
64
       user.person = person
64
       user.person = person
65
       user.email = person.email
65
       user.email = person.email
66
-      user.password = user.password_confirmation = SecureRandom::urlsafe_base64 32
66
+      user.password = user.password_confirmation = SecureRandom.urlsafe_base64 32
67
       user.confirmed = false
67
       user.confirmed = false
68
       user.save!
68
       user.save!
69
     end
69
     end
70
 
70
 
71
-    AuthenticationMailer::password_confirm_email(user).deliver_now
71
+    AuthenticationMailer.password_confirm_email(user).deliver_now
72
     flash_message(:success, I18n.t('authentication.emails.sent'))
72
     flash_message(:success, I18n.t('authentication.emails.sent'))
73
     redirect_to action: 'login'
73
     redirect_to action: 'login'
74
   end
74
   end
84
       redirect_to action: 'forgotten_password_form'
84
       redirect_to action: 'forgotten_password_form'
85
       return
85
       return
86
     end
86
     end
87
-    AuthenticationMailer::password_reset_email(user).deliver_later
87
+    AuthenticationMailer.password_reset_email(user).deliver_later
88
     flash_message(:success, I18n.t('authentication.emails.sent'))
88
     flash_message(:success, I18n.t('authentication.emails.sent'))
89
     redirect_to action: 'login'
89
     redirect_to action: 'login'
90
   end
90
   end

+ 2 - 2
app/models/session.rb

22
   belongs_to :user
22
   belongs_to :user
23
 
23
 
24
   # @return [String] a new random token.
24
   # @return [String] a new random token.
25
-  def Session.new_token
25
+  def self.new_token
26
     SecureRandom.urlsafe_base64
26
     SecureRandom.urlsafe_base64
27
   end
27
   end
28
 
28
 
29
   # @return [String] a BCrypt digest of the given string.
29
   # @return [String] a BCrypt digest of the given string.
30
-  def Session.digest(string)
30
+  def self.digest(string)
31
     cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
31
     cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
32
                                                   BCrypt::Engine.cost
32
                                                   BCrypt::Engine.cost
33
     BCrypt::Password.create(string, cost: cost)
33
     BCrypt::Password.create(string, cost: cost)

+ 1 - 1
app/models/token.rb

45
   def generate_token
45
   def generate_token
46
     candidate = nil
46
     candidate = nil
47
     loop do
47
     loop do
48
-      candidate = SecureRandom::urlsafe_base64 32
48
+      candidate = SecureRandom.urlsafe_base64 32
49
       break candidate unless Token.exists?(token: candidate)
49
       break candidate unless Token.exists?(token: candidate)
50
     end
50
     end
51
     self.token = candidate
51
     self.token = candidate