4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/feature_box/helpers.rb', line 4
def self.define_helpers
return if FeatureBox::Settings.devise_router_name == :feature_box
model_name = FeatureBox::Settings.devise_parent_model.underscore
devise_router_name = FeatureBox::Settings.devise_router_name.to_s
mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq
routes = Devise::URL_HELPERS.slice(*mappings)
routes.each do |module_name, actions|
[:path, :url].each do |path_or_url|
actions.each do |action|
action = action ? "#{action}_" : ""
helper = "#{action}user_#{module_name}_#{path_or_url}"
real_helper = "#{action}#{model_name}_#{module_name}_#{path_or_url}"
class_eval " def \#{helper}\n \#{devise_router_name}.\#{real_helper}\n end\n URL_HELPERS\n end\n end\n end\n\n #We don't need these helpers if user model's name is \"User\"\n return if model_name == 'user'\n \n helpers=[:current_user, :user_session, :user_signed_in?, :authenticate_user!]\n helpers.each do |helper|\n helper = helper.to_s\n real_helper = helper.gsub(/user/,model_name)\n class_eval <<-URL_HELPERS\n def \#{helper} \#{if helper == 'authenticate_user!' then '(opts={})' end}\n \#{real_helper} \#{if helper == 'authenticate_user!' then 'opts' end}\n end\n URL_HELPERS\n end\n\nend\n", __FILE__, __LINE__ + 1
|