Module: Auth::OmniAuth::Path

Defined in:
lib/auth/omniauth/path.rb

Class Method Summary collapse

Class Method Details

.common_callback_path(provider) ⇒ Object

the path for the callback is the same for all models.



74
75
76
# File 'lib/auth/omniauth/path.rb', line 74

def self.common_callback_path(provider)
	"#{omniauth_prefix_path}/#{provider}/callback"
end

.create_or_index_path(cls) ⇒ Object



30
31
32
33
34
# File 'lib/auth/omniauth/path.rb', line 30

def self.create_or_index_path(cls)
	parts = cls.constantize.new.class.name.split("::")
	parts[-1] = parts[-1].pluralize
	parts.map{|c| c.underscore.downcase}.join("_") + "_path"
end

.edit_path(cls) ⇒ Object



36
37
38
# File 'lib/auth/omniauth/path.rb', line 36

def self.edit_path(cls)				
	"edit_" + show_or_update_or_delete_path(cls)
end

.model_to_path(cls) ⇒ Object

given something like :Shopping::Product will return something like shopping/products



55
56
57
58
59
# File 'lib/auth/omniauth/path.rb', line 55

def self.model_to_path(cls)
	parts = cls.to_s.split("::").map{|c| c = c.to_s.downcase}
	parts[-1] = parts[-1].pluralize
	parts.join("/")
end

.new_path(cls) ⇒ Object



18
19
20
# File 'lib/auth/omniauth/path.rb', line 18

def self.new_path(cls)
	"new_" + cls.constantize.new.class.name.underscore.gsub(/\//,"_") + "_path"
end

.omniauth_failure_absolute_pathObject

the absolute path that is returned by the omniauth url helper devise takes care of prepending the resource and the mount prefix.



89
90
91
# File 'lib/auth/omniauth/path.rb', line 89

def self.omniauth_failure_absolute_path
	"omniauth/failed"
end

.omniauth_failure_route_path(resource_or_scope) ⇒ Object

this is the path that is used in the routes.rb file, to build the actual route. keeps :res as a wildcard for the required resource.



96
97
98
99
# File 'lib/auth/omniauth/path.rb', line 96

def self.omniauth_failure_route_path(resource_or_scope)
	resource_or_scope = resource_or_scope.nil? ? ":res" : resource_pluralized(resource_or_scope.class.name)
	"#{Auth.configuration.mount_path}/#{resource_or_scope}/#{omniauth_failure_absolute_path}"
end

.omniauth_prefix_pathObject

the omniauth prefix = mount_path/omniauth



69
70
71
# File 'lib/auth/omniauth/path.rb', line 69

def self.omniauth_prefix_path
	"#{Auth.configuration.mount_path}/omniauth"
end

.omniauth_request_path(resource, provider) ⇒ Object

the the path for the request_phase of the omniauth call.



62
63
64
65
66
# File 'lib/auth/omniauth/path.rb', line 62

def self.omniauth_request_path(resource,provider)
	resource_or_scope = resource.nil? ? ":res" : 
	resource_pluralized(resource)
	"#{omniauth_prefix_path}/#{resource_or_scope}/#{provider}"
end

.path_to_model(path) ⇒ Object

given something like : shopping/product will return something like: Shopping::Product



49
50
51
# File 'lib/auth/omniauth/path.rb', line 49

def self.path_to_model(path)
	path.split("/").map{|c| c = c.capitalize}.join("::").constantize
end

.pathify(cls_name_as_string) ⇒ Object

FOR BUILDING THE PATHS FOR ALL CLASSES.

given something like Auth::Shopping::CartItem , will return auth/shopping/cart_item @param cls_name_as_string : the name of the class , as a string. @retunrn the pathified version of the class name.



13
14
15
# File 'lib/auth/omniauth/path.rb', line 13

def self.pathify(cls_name_as_string)
	cls_name_as_string.split("::").map{|c| c = c.underscore}.join("/")
end

.resource_path(resource) ⇒ Object

the path prefix for all the devise modules.



83
84
85
# File 'lib/auth/omniauth/path.rb', line 83

def self.resource_path(resource)	
	"#{Auth.configuration.mount_path}/#{resource_pluralized resource}"
end

.resource_pluralized(resource) ⇒ Object



78
79
80
# File 'lib/auth/omniauth/path.rb', line 78

def self.resource_pluralized(resource)
	resource.to_s.pluralize.underscore.gsub('/', '_')
end

.show_or_update_or_delete_path(cls) ⇒ Object



23
24
25
26
27
# File 'lib/auth/omniauth/path.rb', line 23

def self.show_or_update_or_delete_path(cls)
	
	parts = cls.constantize.new.class.name.split("::")
	parts.map{|c| c.underscore.downcase}.join("_") + "_path"
end