ソースを参照

Guard clause, if-unless, parentheses

Maarten van den Berg 6 年 前
コミット
4eeccb1671

+ 0 - 33
.rubocop.yml

162
 Style/FrozenStringLiteralComment:
162
 Style/FrozenStringLiteralComment:
163
   Enabled: false
163
   Enabled: false
164
 
164
 
165
-# Offense count: 14
166
-# Configuration parameters: MinBodyLength.
167
-Style/GuardClause:
168
-  Exclude:
169
-    - 'app/controllers/people_controller.rb'
170
-    - 'app/helpers/activities_helper.rb'
171
-    - 'app/helpers/authentication_helper.rb'
172
-    - 'app/helpers/groups_helper.rb'
173
-    - 'app/models/activity.rb'
174
-    - 'app/models/person.rb'
175
-    - 'app/models/user.rb'
176
-
177
 # Offense count: 1
165
 # Offense count: 1
178
 # Cop supports --auto-correct.
166
 # Cop supports --auto-correct.
179
 # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
167
 # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
182
   Exclude:
170
   Exclude:
183
     - 'lib/tasks/sessions.rake'
171
     - 'lib/tasks/sessions.rake'
184
 
172
 
185
-# Offense count: 20
186
-# Cop supports --auto-correct.
187
-Style/IfUnlessModifier:
188
-  Exclude:
189
-    - 'app/controllers/activities_controller.rb'
190
-    - 'app/controllers/authentication_controller.rb'
191
-    - 'app/controllers/people_controller.rb'
192
-    - 'app/helpers/authentication_helper.rb'
193
-    - 'app/models/activity.rb'
194
-    - 'app/models/person.rb'
195
-    - 'app/models/user.rb'
196
-    - 'config/puma.rb'
197
-
198
-# Offense count: 1
199
-# Cop supports --auto-correct.
200
-# Configuration parameters: EnforcedStyle.
201
-# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
202
-Style/MethodDefParentheses:
203
-  Exclude:
204
-    - 'app/helpers/dashboard_helper.rb'
205
-
206
 # Offense count: 2
173
 # Offense count: 2
207
 Style/MixinUsage:
174
 Style/MixinUsage:
208
   Exclude:
175
   Exclude:

+ 2 - 6
app/controllers/activities_controller.rb

127
 
127
 
128
   # POST /activities/1/immediate_subgroups
128
   # POST /activities/1/immediate_subgroups
129
   def immediate_subgroups
129
   def immediate_subgroups
130
-    if params[:overwrite]
131
-      @activity.clear_subgroups!
132
-    end
130
+    @activity.clear_subgroups! if params[:overwrite]
133
 
131
 
134
     @activity.assign_subgroups!
132
     @activity.assign_subgroups!
135
 
133
 
284
       return
282
       return
285
     end
283
     end
286
 
284
 
287
-    if params[:participant]
288
-      params[:notes] = params[:participant][:notes]
289
-    end
285
+    params[:notes] = params[:participant][:notes] if params[:participant]
290
     participant.update_attributes(params.permit(:notes, :attending))
286
     participant.update_attributes(params.permit(:notes, :attending))
291
     head :no_content
287
     head :no_content
292
   end
288
   end

+ 1 - 3
app/controllers/authentication_controller.rb

91
 
91
 
92
   def reset_password_form
92
   def reset_password_form
93
     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
93
     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
94
-    unless token_valid? token
95
-      return
96
-    end
94
+    return unless token_valid? token
97
 
95
 
98
     render layout: 'void'
96
     render layout: 'void'
99
   end
97
   end

+ 1 - 3
app/controllers/people_controller.rb

13
   # GET /people/1
13
   # GET /people/1
14
   # GET /people/1.json
14
   # GET /people/1.json
15
   def show
15
   def show
16
-    if @person != current_person
17
-      require_admin!
18
-    end
16
+    require_admin! if @person != current_person
19
   end
17
   end
20
 
18
 
21
   # GET /people/new
19
   # GET /people/new

+ 2 - 6
app/helpers/authentication_helper.rb

74
 
74
 
75
         get_user_session
75
         get_user_session
76
 
76
 
77
-        if @user_session.nil? || @user_session.remember_digest.nil?
78
-          return false
79
-        end
77
+        return false if @user_session.nil? || @user_session.remember_digest.nil?
80
 
78
 
81
         session_password = BCrypt::Password.new @user_session.remember_digest
79
         session_password = BCrypt::Password.new @user_session.remember_digest
82
 
80
 
103
     end
101
     end
104
 
102
 
105
     # Edge case if a session no longer exists in the database
103
     # Edge case if a session no longer exists in the database
106
-    unless @user_session
107
-      log_out(session_broken: true)
108
-    end
104
+    log_out(session_broken: true) unless @user_session
109
   end
105
   end
110
 
106
 
111
   def current_user
107
   def current_user

+ 1 - 1
app/helpers/dashboard_helper.rb

1
 module DashboardHelper
1
 module DashboardHelper
2
-  def xeditable? obj = nil
2
+  def xeditable?(obj = nil)
3
     obj.may_change?(current_person)
3
     obj.may_change?(current_person)
4
   end
4
   end
5
 end
5
 end

+ 8 - 24
app/models/activity.rb

137
   #  2. do not have Participants (and thus, no way to confirm) yet
137
   #  2. do not have Participants (and thus, no way to confirm) yet
138
   def create_missing_participants!
138
   def create_missing_participants!
139
     people = self.group.people
139
     people = self.group.people
140
-    unless self.participants.empty?
141
-      people = people.where('people.id NOT IN (?)', self.people.ids)
142
-    end
140
+    people = people.where('people.id NOT IN (?)', self.people.ids) unless self.participants.empty?
143
 
141
 
144
     people.each do |p|
142
     people.each do |p|
145
       Participant.create(
143
       Participant.create(
198
         a.reminder_at = Time.zone.local(rd.year, rd.month, rd.day, rt.hour, rt.min)
196
         a.reminder_at = Time.zone.local(rd.year, rd.month, rd.day, rt.hour, rt.min)
199
       end
197
       end
200
 
198
 
201
-      unless row['subgroup_division_enabled'].blank?
202
-        a.subgroup_division_enabled = row['subgroup_division_enabled'].casecmp('y').zero?
203
-      end
199
+      a.subgroup_division_enabled = row['subgroup_division_enabled'].casecmp('y').zero? unless row['subgroup_division_enabled'].blank?
204
 
200
 
205
-      unless row['no_response_action'].blank?
206
-        a.no_response_action = row['no_response_action'].casecmp('p').zero?
207
-      end
201
+      a.no_response_action = row['no_response_action'].casecmp('p').zero? unless row['no_response_action'].blank?
208
 
202
 
209
       result << a
203
       result << a
210
     end
204
     end
271
       groups.first[0] += 1
265
       groups.first[0] += 1
272
     end
266
     end
273
 
267
 
274
-    if mail
275
-      self.notify_subgroups!
276
-    end
268
+    self.notify_subgroups! if mail
277
   end
269
   end
278
 
270
 
279
   def clear_subgroups!(only_assignable = true)
271
   def clear_subgroups!(only_assignable = true)
310
   # Assert that the deadline for participants to change the deadline, if any,
302
   # Assert that the deadline for participants to change the deadline, if any,
311
   # is set before the event starts.
303
   # is set before the event starts.
312
   def deadline_before_start
304
   def deadline_before_start
313
-    if self.deadline > self.start
314
-      errors.add(:deadline, I18n.t('activities.errors.must_be_before_start'))
315
-    end
305
+    errors.add(:deadline, I18n.t('activities.errors.must_be_before_start')) if self.deadline > self.start
316
   end
306
   end
317
 
307
 
318
   # Assert that the activity's end, if any, occurs after the event's start.
308
   # Assert that the activity's end, if any, occurs after the event's start.
319
   def end_after_start
309
   def end_after_start
320
-    if self.end < self.start
321
-      errors.add(:end, I18n.t('activities.errors.must_be_after_start'))
322
-    end
310
+    errors.add(:end, I18n.t('activities.errors.must_be_after_start')) if self.end < self.start
323
   end
311
   end
324
 
312
 
325
   # Assert that the reminder for non-response is sent while participants still
313
   # Assert that the reminder for non-response is sent while participants still
326
   # can change their response.
314
   # can change their response.
327
   def reminder_before_deadline
315
   def reminder_before_deadline
328
-    if self.reminder_at > self.deadline
329
-      errors.add(:reminder_at, I18n.t('activities.errors.must_be_before_deadline'))
330
-    end
316
+    errors.add(:reminder_at, I18n.t('activities.errors.must_be_before_deadline')) if self.reminder_at > self.deadline
331
   end
317
   end
332
 
318
 
333
   # Assert that there is at least one divisible subgroup.
319
   # Assert that there is at least one divisible subgroup.
334
   def subgroups_for_division_present
320
   def subgroups_for_division_present
335
-    if self.subgroups.where(is_assignable: true).none? && subgroup_division_enabled?
336
-      errors.add(:subgroup_division_enabled, I18n.t('activities.errors.cannot_divide_without_subgroups'))
337
-    end
321
+    errors.add(:subgroup_division_enabled, I18n.t('activities.errors.cannot_divide_without_subgroups')) if self.subgroups.where(is_assignable: true).none? && subgroup_division_enabled?
338
   end
322
   end
339
 end
323
 end

+ 3 - 9
app/models/person.rb

135
       # Response
135
       # Response
136
       yourresponse = "#{I18n.t 'activities.participant.yourresponse'}: #{p.human_attending}"
136
       yourresponse = "#{I18n.t 'activities.participant.yourresponse'}: #{p.human_attending}"
137
 
137
 
138
-      if p.notes.present?
139
-        yourresponse << " (#{p.notes})"
140
-      end
138
+      yourresponse << " (#{p.notes})" if p.notes.present?
141
 
139
 
142
       description_items << yourresponse
140
       description_items << yourresponse
143
 
141
 
157
 
155
 
158
       # Subgroups
156
       # Subgroups
159
       if a.subgroups.any?
157
       if a.subgroups.any?
160
-        if p.subgroup
161
-          description_items << "#{I18n.t 'activities.participant.yoursubgroup'}: #{p.subgroup}"
162
-        end
158
+        description_items << "#{I18n.t 'activities.participant.yoursubgroup'}: #{p.subgroup}" if p.subgroup
163
 
159
 
164
         subgroup_names = a.subgroups.map(&:name).join ', '
160
         subgroup_names = a.subgroups.map(&:name).join ', '
165
         description_items << "#{I18n.t 'activerecord.models.subgroup.other'}: #{subgroup_names}"
161
         description_items << "#{I18n.t 'activerecord.models.subgroup.other'}: #{subgroup_names}"
194
 
190
 
195
   # Assert that the person's birth date, if any, lies in the past.
191
   # Assert that the person's birth date, if any, lies in the past.
196
   def birth_date_cannot_be_in_future
192
   def birth_date_cannot_be_in_future
197
-    if self.birth_date && self.birth_date > Date.today
198
-      errors.add(:birth_date, I18n.t('person.errors.cannot_future'))
199
-    end
193
+    errors.add(:birth_date, I18n.t('person.errors.cannot_future')) if self.birth_date && self.birth_date > Date.today
200
   end
194
   end
201
 
195
 
202
   # Explicitly force nil to false in the admin field.
196
   # Explicitly force nil to false in the admin field.

+ 1 - 3
app/models/user.rb

30
   # Assert that the user's email address is the same as the email address of
30
   # Assert that the user's email address is the same as the email address of
31
   # the associated Person.
31
   # the associated Person.
32
   def email_same_as_person
32
   def email_same_as_person
33
-    if self.person && (self.email != self.person.email)
34
-      errors.add(:email, I18n.t('authentication.user_person_mail_mismatch'))
35
-    end
33
+    errors.add(:email, I18n.t('authentication.user_person_mail_mismatch')) if self.person && (self.email != self.person.email)
36
   end
34
   end
37
 end
35
 end

+ 1 - 3
config/puma.rb

17
 environment env
17
 environment env
18
 
18
 
19
 state_path "#{ENV['AARDBEI_PATH']}/tmp/pids/puma.state"
19
 state_path "#{ENV['AARDBEI_PATH']}/tmp/pids/puma.state"
20
-if env == "production"
21
-  stdout_redirect "#{ENV['AARDBEI_PATH']}/log/stdout", "#{ENV['AARDBEI_PATH']}/log/stderr", true
22
-end
20
+stdout_redirect "#{ENV['AARDBEI_PATH']}/log/stdout", "#{ENV['AARDBEI_PATH']}/log/stderr", true if env == "production"
23
 
21
 
24
 # Specifies the number of `workers` to boot in clustered mode.
22
 # Specifies the number of `workers` to boot in clustered mode.
25
 # Workers are forked webserver processes. If using threads and workers together
23
 # Workers are forked webserver processes. If using threads and workers together