From a9e87f067a2a89977930df8f78db48cfeb50d683 Mon Sep 17 00:00:00 2001 From: Stephen Baldwin Date: Thu, 20 Nov 2014 15:16:46 -0500 Subject: [PATCH 1/2] Ability to load modules in specific order Allow modules to be inserted at set positions --- lib/devise.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/devise.rb b/lib/devise.rb index 5a6fa9db..6bb89844 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -348,6 +348,7 @@ module Devise # +controller+ - Symbol representing the name of an existing or custom *controller* for this module. # +route+ - Symbol representing the named *route* helper for this module. # +strategy+ - Symbol representing if this module got a custom *strategy*. + # +insert_at+ - Integer representing the order in which this module's model will be included # # All values, except :model, accept also a boolean and will have the same name as the given module # name. @@ -357,10 +358,16 @@ module Devise # Devise.add_module(:party_module) # Devise.add_module(:party_module, strategy: true, controller: :sessions) # Devise.add_module(:party_module, model: 'party_module/model') + # Devise.add_module(:party_module, insert_at: 0) # def self.add_module(module_name, options = {}) - ALL << module_name - options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input) + options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input, :insert_at) + + if insert_at = options[:insert_at] + ALL.insert insert_at, module_name + else + ALL << module_name + end if strategy = options[:strategy] strategy = (strategy == true ? module_name : strategy) From 06e0f8adca227eb170a95e9dac25c3e907e8b3ad Mon Sep 17 00:00:00 2001 From: Stephen Baldwin Date: Thu, 20 Nov 2014 16:01:21 -0500 Subject: [PATCH 2/2] Update devise.rb --- lib/devise.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/devise.rb b/lib/devise.rb index 6bb89844..3be7f325 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -363,11 +363,7 @@ module Devise def self.add_module(module_name, options = {}) options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input, :insert_at) - if insert_at = options[:insert_at] - ALL.insert insert_at, module_name - else - ALL << module_name - end + ALL.insert (options[:insert_at] || -1), module_name if strategy = options[:strategy] strategy = (strategy == true ? module_name : strategy)