Browse Source

Conditional assignment

Maarten van den Berg 6 years ago
parent
commit
4965be6ee1

+ 0 - 12
.rubocop.yml

@@ -58,18 +58,6 @@ Style/ColonMethodCall:
58 58
     - 'app/controllers/authentication_controller.rb'
59 59
     - 'app/models/token.rb'
60 60
 
61
-# Offense count: 9
62
-# Cop supports --auto-correct.
63
-# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
64
-# SupportedStyles: assign_to_condition, assign_inside_condition
65
-Style/ConditionalAssignment:
66
-  Exclude:
67
-    - 'app/controllers/activities_controller.rb'
68
-    - 'app/controllers/api/activities_controller.rb'
69
-    - 'app/controllers/groups_controller.rb'
70
-    - 'app/mailers/participant_mailer.rb'
71
-    - 'db/seeds.rb'
72
-
73 61
 # Offense count: 55
74 62
 Style/Documentation:
75 63
   Enabled: false

+ 11 - 15
app/controllers/activities_controller.rb

@@ -24,17 +24,17 @@ class ActivitiesController < ApplicationController
24 24
   # GET /groups/:id/activities
25 25
   # GET /activities.json
26 26
   def index
27
-    if params[:past]
28
-      @activities = @group.activities
27
+    @activities = if params[:past]
28
+                    @group.activities
29 29
                           .where('start < ?', Time.now)
30 30
                           .order(start: :desc)
31 31
                           .paginate(page: params[:page], per_page: 25)
32
-    else
33
-      @activities = @group.activities
32
+                  else
33
+                    @group.activities
34 34
                           .where('start > ?', Time.now)
35 35
                           .order(start: :asc)
36 36
                           .paginate(page: params[:page], per_page: 25)
37
-    end
37
+                  end
38 38
   end
39 39
 
40 40
   # GET /activities/1
@@ -111,11 +111,7 @@ class ActivitiesController < ApplicationController
111 111
           raise ActiveRecord::Rollback
112 112
         end
113 113
 
114
-        if v != 'nil'
115
-          p.subgroup = sg
116
-        else
117
-          p.subgroup = nil
118
-        end
114
+        p.subgroup = (sg if v != 'nil')
119 115
 
120 116
         p.save
121 117
       end
@@ -190,11 +186,11 @@ class ActivitiesController < ApplicationController
190 186
     @participant.is_organizer = params[:new_state]
191 187
     @participant.save
192 188
 
193
-    if params[:new_state] == "true"
194
-      message = I18n.t('activities.organizers.added', name: @participant.person.full_name)
195
-    else
196
-      message = I18n.t('activities.organizers.removed', name: @participant.person.full_name)
197
-    end
189
+    message = if params[:new_state] == "true"
190
+                I18n.t('activities.organizers.added', name: @participant.person.full_name)
191
+              else
192
+                I18n.t('activities.organizers.removed', name: @participant.person.full_name)
193
+              end
198 194
     flash_message(:success, message)
199 195
 
200 196
     redirect_to edit_group_activity_path(@group, @activity, anchor: 'organizers-add')

+ 17 - 17
app/controllers/api/activities_controller.rb

@@ -40,23 +40,23 @@ module Api
40 40
 
41 41
       absentnames = absent.map { |p| p.person.first_name }
42 42
 
43
-      if presentnames.positive?
44
-        present_mess = I18n.t('activities.participant.these_present', count: present.count, names: presentnames.join(', '))
45
-      else
46
-        present_mess = I18n.t('activities.participant.none_present')
47
-      end
48
-
49
-      if unknownnames.positive?
50
-        unknown_mess = I18n.t('activities.participant.these_unknown', count: unknown.count, names: unknownnames.join(', '))
51
-      else
52
-        unknown_mess = I18n.t('activities.participant.none_unknown')
53
-      end
54
-
55
-      if absentnames.positive?
56
-        absent_mess = I18n.t('activities.participant.these_absent', count: absent.count, names: absentnames.join(', '))
57
-      else
58
-        absent_mess = I18n.t('activities.participant.none_absent')
59
-      end
43
+      present_mess = if presentnames.positive?
44
+                       I18n.t('activities.participant.these_present', count: present.count, names: presentnames.join(', '))
45
+                     else
46
+                       I18n.t('activities.participant.none_present')
47
+                     end
48
+
49
+      unknown_mess = if unknownnames.positive?
50
+                       I18n.t('activities.participant.these_unknown', count: unknown.count, names: unknownnames.join(', '))
51
+                     else
52
+                       I18n.t('activities.participant.none_unknown')
53
+                     end
54
+
55
+      absent_mess = if absentnames.positive?
56
+                      I18n.t('activities.participant.these_absent', count: absent.count, names: absentnames.join(', '))
57
+                    else
58
+                      I18n.t('activities.participant.none_absent')
59
+                    end
60 60
 
61 61
       @summary = {
62 62
         present: {

+ 5 - 5
app/controllers/groups_controller.rb

@@ -27,11 +27,11 @@ class GroupsController < ApplicationController
27 27
                             .where('activities.group_id': @group.id)
28 28
                             .where('start > ?', Date.today)
29 29
 
30
-    if @organized_activities.any?
31
-      @groupmenu = 'col-md-6'
32
-    else
33
-      @groupmenu = 'col-md-12'
34
-    end
30
+    @groupmenu = if @organized_activities.any?
31
+                   'col-md-6'
32
+                 else
33
+                   'col-md-12'
34
+                 end
35 35
 
36 36
     @upcoming = @group.activities
37 37
                       .where('start > ?', Date.today)

+ 5 - 5
app/mailers/participant_mailer.rb

@@ -3,11 +3,11 @@ class ParticipantMailer < ApplicationMailer
3 3
     @person = person
4 4
     @activity = activity
5 5
 
6
-    if activity.no_response_action # is true
7
-      key = 'activities.emails.attendance_reminder.subject_present'
8
-    else
9
-      key = 'activities.emails.attendance_reminder.subject_absent'
10
-    end
6
+    key = if activity.no_response_action # is true
7
+            'activities.emails.attendance_reminder.subject_present'
8
+          else
9
+            'activities.emails.attendance_reminder.subject_absent'
10
+          end
11 11
 
12 12
     subject = I18n.t(key, activity: @activity.name)
13 13
 

+ 1 - 5
db/seeds.rb

@@ -91,11 +91,7 @@ Person.all.each do |p|
91 91
       is_leader: Faker::Boolean.boolean(0.1)
92 92
     )
93 93
     g.activities.each do |a|
94
-      if Faker::Boolean.boolean(0.15)
95
-        notes = Faker::Hipster.sentence
96
-      else
97
-        notes = nil
98
-      end
94
+      notes = (Faker::Hipster.sentence if Faker::Boolean.boolean(0.15))
99 95
 
100 96
       # Participants are created on adding to group, no need to create
101 97
       part = Participant.find_by(