2009-10-18 09:15:23 -04:00
|
|
|
module Devise
|
|
|
|
module Strategies
|
2009-11-14 23:13:54 -05:00
|
|
|
# Base strategy for Devise. Responsible for verifying correct scope and mapping.
|
2009-11-14 21:13:43 -05:00
|
|
|
module Base
|
2009-10-18 09:15:23 -04:00
|
|
|
# Validate strategy. By default will raise an error if no scope or an
|
|
|
|
# invalid mapping is found.
|
|
|
|
def valid?
|
2009-11-15 17:07:47 -05:00
|
|
|
raise "Could not find mapping for #{scope}" unless mapping
|
2009-11-14 21:13:43 -05:00
|
|
|
mapping.for.include?(klass_type)
|
2009-10-18 09:15:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Checks if a valid scope was given for devise and find mapping based on
|
|
|
|
# this scope.
|
|
|
|
def mapping
|
2009-11-14 23:13:54 -05:00
|
|
|
Devise.mappings[scope]
|
2009-11-14 21:13:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# Store this class type.
|
|
|
|
def klass_type
|
|
|
|
@klass_type ||= self.class.name.split("::").last.underscore.to_sym
|
2009-10-18 09:15:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|