1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/lib/devise/strategies/base.rb

33 lines
875 B
Ruby
Raw Normal View History

2009-10-18 09:15:23 -04:00
module Devise
module Strategies
# Base strategy for Devise. Responsible for verifying correct scope and mapping.
2010-01-14 09:47:14 -05:00
class Base < ::Warden::Strategies::Base
# Checks if a valid scope was given for devise and find mapping based on this scope.
2009-10-18 09:15:23 -04:00
def mapping
@mapping ||= begin
mapping = Devise.mappings[scope]
raise "Could not find mapping for #{scope}" unless mapping
mapping
end
2009-10-18 09:15:23 -04:00
end
protected
def succeeded?
@result == :success
end
# Simply invokes valid_for_authentication? with the given block and deal with the result.
def validate(resource, &block)
result = resource && resource.valid_for_authentication?(&block)
case result
when Symbol, String
fail!(result)
else
result
end
end
2009-10-18 09:15:23 -04:00
end
end
end