Module: Nyauth::ApplicationHelper
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'app/helpers/nyauth/application_helper.rb', line 3
def method_missing method, *args, &block
if method =~ /(.+)_path_for\z/
detect_url_helper($1, *args)
elsif method =~ /(_url|_path)\z/
main_app.send(method, *args)
else
super
end
end
|
Instance Method Details
#detect_url_helper(feature, client_name, *args) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'app/helpers/nyauth/application_helper.rb', line 14
def detect_url_helper(feature, client_name, *args)
@__methods ||= Nyauth::Engine.routes.url_helpers.instance_methods + Rails.application.routes.url_helpers.instance_methods
@__candidates ||= @__methods.reject{|m| m =~ /\A(:?rails_|_)/}.map(&:to_s)
if client_name.to_sym == :user
detect_url_helper_for_nyauth(feature, *args)
else
detect_url_helper_for_app(feature, client_name, *args)
end
end
|
#detect_url_helper_for_app(feature, client_name, *args) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'app/helpers/nyauth/application_helper.rb', line 30
def detect_url_helper_for_app(feature, client_name, *args)
if feature =~ /new_(.+)/
path = @__candidates.grep(/\Anew_#{client_name}_#{$1}_path\z/).first
else
path = @__candidates.grep(/\A#{client_name}_#{feature}_path\z/).first
end
return nil unless path
__send__(path, *args)
end
|
#detect_url_helper_for_nyauth(feature, *args) ⇒ Object
24
25
26
27
28
|
# File 'app/helpers/nyauth/application_helper.rb', line 24
def detect_url_helper_for_nyauth(feature, *args)
path = @__candidates.grep(/\A#{feature}_path\z/).first
return nil unless path
nyauth.__send__(path, *args)
end
|
#root_path ⇒ Object
40
41
42
43
44
45
46
|
# File 'app/helpers/nyauth/application_helper.rb', line 40
def root_path
if main_app.respond_to?(:root_path)
main_app.__send__(:root_path)
else
'/'
end
end
|