From 13dfd2dff6f892cd2376ce6cd91395215e414ffb Mon Sep 17 00:00:00 2001 From: Francois Chagnon Date: Wed, 26 Feb 2014 20:52:38 +0000 Subject: [PATCH] do not use constantize, use more verbose approach --- app/controllers/apps_controller.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/apps_controller.rb b/app/controllers/apps_controller.rb index abdc458..04bea0a 100644 --- a/app/controllers/apps_controller.rb +++ b/app/controllers/apps_controller.rb @@ -90,8 +90,10 @@ class AppsController < ApplicationController def initialize_subclassed_issue_tracker # set the app's issue tracker if params[:app][:issue_tracker_attributes] && tracker_type = params[:app][:issue_tracker_attributes][:type] - if IssueTracker.subclasses.map(&:name).concat(["IssueTracker"]).include?(tracker_type) - app.issue_tracker = tracker_type.constantize.new(params[:app][:issue_tracker_attributes]) + available_tracker_classes = [IssueTracker] + IssueTracker.subclasses + tracker_class = available_tracker_classes.detect{|c| c.name == tracker_type} + if !tracker_class.nil? + app.issue_tracker = tracker_class.new(params[:app][:issue_tracker_attributes]) end end end @@ -99,8 +101,10 @@ class AppsController < ApplicationController def initialize_subclassed_notification_service # set the app's notification service if params[:app][:notification_service_attributes] && notification_type = params[:app][:notification_service_attributes][:type] - if NotificationService.subclasses.map(&:name).concat(["NotificationService"]).include?(notification_type) - app.notification_service = notification_type.constantize.new(params[:app][:notification_service_attributes]) + available_notification_classes = [NotificationService] + NotificationService.subclasses + notification_class = available_notification_classes.detect{|c| c.name == tracker_type} + if !notification_class.nil? + app.notification_service = notification_class.new(params[:app][:notification_service_attributes]) end end end -- libgit2 0.21.2