Browse Source

Proc style, redundant returns

Maarten van den Berg 6 years ago
parent
commit
14aef99d0e

+ 0 - 20
.rubocop.yml

246
   Exclude:
246
   Exclude:
247
     - 'db/seeds.rb'
247
     - 'db/seeds.rb'
248
 
248
 
249
-# Offense count: 5
250
-# Cop supports --auto-correct.
251
-# Configuration parameters: AllowMultipleReturnValues.
252
-Style/RedundantReturn:
253
-  Exclude:
254
-    - 'app/helpers/authentication_helper.rb'
255
-    - 'app/models/activity.rb'
256
-    - 'app/models/person.rb'
257
-
258
 # Offense count: 85
249
 # Offense count: 85
259
 # Cop supports --auto-correct.
250
 # Cop supports --auto-correct.
260
 Style/RedundantSelf:
251
 Style/RedundantSelf:
282
 Style/SymbolArray:
273
 Style/SymbolArray:
283
   EnforcedStyle: brackets
274
   EnforcedStyle: brackets
284
 
275
 
285
-# Offense count: 5
286
-# Cop supports --auto-correct.
287
-# Configuration parameters: IgnoredMethods.
288
-# IgnoredMethods: respond_to, define_method
289
-Style/SymbolProc:
290
-  Exclude:
291
-    - 'app/controllers/activities_controller.rb'
292
-    - 'app/models/activity.rb'
293
-    - 'app/models/member.rb'
294
-    - 'db/migrate/20180904163645_generate_calendar_tokens.rb'
295
-
296
 # Offense count: 3
276
 # Offense count: 3
297
 # Cop supports --auto-correct.
277
 # Cop supports --auto-correct.
298
 # Configuration parameters: WordRegex.
278
 # Configuration parameters: WordRegex.

+ 1 - 3
app/controllers/activities_controller.rb

298
     uploaded_io = params[:spreadsheet]
298
     uploaded_io = params[:spreadsheet]
299
     result = Activity.from_csv(uploaded_io.read, @group)
299
     result = Activity.from_csv(uploaded_io.read, @group)
300
 
300
 
301
-    result.each do |a|
302
-      a.save!
303
-    end
301
+    result.each(&:save!)
304
 
302
 
305
     flash_message(:success, I18n.t('activities.mass_imported', count: result.count))
303
     flash_message(:success, I18n.t('activities.mass_imported', count: result.count))
306
     redirect_to group_activities_path(@group)
304
     redirect_to group_activities_path(@group)

+ 3 - 3
app/helpers/authentication_helper.rb

64
 
64
 
65
       return false if !@user_session.active || @user_session.expires < Time.now
65
       return false if !@user_session.active || @user_session.expires < Time.now
66
 
66
 
67
-      return true
67
+      true
68
 
68
 
69
     else
69
     else
70
       # Case 2: User is returning and has a remember token saved.
70
       # Case 2: User is returning and has a remember token saved.
89
         return false
89
         return false
90
       end
90
       end
91
 
91
 
92
-      return false
92
+      false
93
     end
93
     end
94
   end
94
   end
95
 
95
 
127
     Raven.user_context(
127
     Raven.user_context(
128
       user_firstname: current_person.first_name
128
       user_firstname: current_person.first_name
129
     )
129
     )
130
-    return true
130
+    true
131
   end
131
   end
132
 
132
 
133
   def require_admin!
133
   def require_admin!

+ 3 - 5
app/models/activity.rb

122
     p = c[true]
122
     p = c[true]
123
     a = c[false]
123
     a = c[false]
124
     u = c[nil]
124
     u = c[nil]
125
-    return "#{p || 0}, #{a || 0}, #{u || 0}"
125
+    "#{p || 0}, #{a || 0}, #{u || 0}"
126
   end
126
   end
127
 
127
 
128
   # Determine whether the passed Person may change this activity.
128
   # Determine whether the passed Person may change this activity.
220
     return if self.reminder_at > Time.zone.now
220
     return if self.reminder_at > Time.zone.now
221
 
221
 
222
     participants = self.participants.where(attending: nil)
222
     participants = self.participants.where(attending: nil)
223
-    participants.each { |p| p.send_reminder }
223
+    participants.each(&:send_reminder)
224
 
224
 
225
     self.reminder_done = true
225
     self.reminder_done = true
226
     self.save
226
     self.save
302
          .joins(:person)
302
          .joins(:person)
303
          .where.not(subgroup: nil)
303
          .where.not(subgroup: nil)
304
 
304
 
305
-    ps.each do |pp|
306
-      pp.send_subgroup_notification
307
-    end
305
+    ps.each(&:send_subgroup_notification)
308
   end
306
   end
309
 
307
 
310
   private
308
   private

+ 1 - 3
app/models/member.rb

44
       activity: self.group.future_activities
44
       activity: self.group.future_activities
45
     )
45
     )
46
 
46
 
47
-    participants.each do |p|
48
-      p.destroy!
49
-    end
47
+    participants.each(&:destroy!)
50
   end
48
   end
51
 end
49
 end

+ 1 - 1
app/models/person.rb

94
       result << p
94
       result << p
95
     end
95
     end
96
 
96
 
97
-    return result
97
+    result
98
   end
98
   end
99
 
99
 
100
   # @return [String]
100
   # @return [String]

+ 1 - 3
db/migrate/20180904163645_generate_calendar_tokens.rb

1
 class GenerateCalendarTokens < ActiveRecord::Migration[5.0]
1
 class GenerateCalendarTokens < ActiveRecord::Migration[5.0]
2
   def up
2
   def up
3
-    Person.all.each do |p|
4
-      p.regenerate_calendar_token
5
-    end
3
+    Person.all.each(&:regenerate_calendar_token)
6
   end
4
   end
7
 
5
 
8
   def down; end
6
   def down; end