Commit 13dfd2dff6f892cd2376ce6cd91395215e414ffb
1 parent
a4c53efd
Exists in
master
and in
1 other branch
do not use constantize, use more verbose approach
Showing
1 changed file
with
8 additions
and
4 deletions
Show diff stats
app/controllers/apps_controller.rb
| ... | ... | @@ -90,8 +90,10 @@ class AppsController < ApplicationController |
| 90 | 90 | def initialize_subclassed_issue_tracker |
| 91 | 91 | # set the app's issue tracker |
| 92 | 92 | if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type] |
| 93 | - if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type) | |
| 94 | - app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes]) | |
| 93 | + available_tracker_classes = [IssueTracker] + IssueTracker.subclasses | |
| 94 | + tracker_class = available_tracker_classes.detect{|c| c.name == tracker_type} | |
| 95 | + if !tracker_class.nil? | |
| 96 | + app.issue_tracker = tracker_class.new(params[:app][:issue_tracker_attributes]) | |
| 95 | 97 | end |
| 96 | 98 | end |
| 97 | 99 | end |
| ... | ... | @@ -99,8 +101,10 @@ class AppsController < ApplicationController |
| 99 | 101 | def initialize_subclassed_notification_service |
| 100 | 102 | # set the app's notification service |
| 101 | 103 | if params[:app][:notification_service_attributes] && notification_type = params[:app][:notification_service_attributes][:type] |
| 102 | - if NotificationService.subclasses.map(&:name).concat(["NotificationService"]).include?(notification_type) | |
| 103 | - app.notification_service = notification_type.constantize.new(params[:app][:notification_service_attributes]) | |
| 104 | + available_notification_classes = [NotificationService] + NotificationService.subclasses | |
| 105 | + notification_class = available_notification_classes.detect{|c| c.name == tracker_type} | |
| 106 | + if !notification_class.nil? | |
| 107 | + app.notification_service = notification_class.new(params[:app][:notification_service_attributes]) | |
| 104 | 108 | end |
| 105 | 109 | end |
| 106 | 110 | end | ... | ... |