Commit 3ee8e019 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extract token authenticatable strategy fabrication

parent f1a74a65
......@@ -20,13 +20,8 @@ module TokenAuthenticatable
attr_accessor :cleartext_tokens
strategy = if options[:digest]
TokenAuthenticatableStrategies::Digest.new(self, token_field, options)
elsif options[:encrypted]
TokenAuthenticatableStrategies::Encrypted.new(self, token_field, options)
else
TokenAuthenticatableStrategies::Insecure.new(self, token_field, options)
end
strategy = TokenAuthenticatableStrategies::Base
.fabricate(self, token_field, options)
if unique
define_singleton_method("find_by_#{token_field}") do |token|
......
......@@ -43,6 +43,16 @@ module TokenAuthenticatableStrategies
options[:fallback] == true
end
def self.fabricate(instance, field, options)
if options[:digest]
TokenAuthenticatableStrategies::Digest.new(instance, field, options)
elsif options[:encrypted]
TokenAuthenticatableStrategies::Encrypted.new(instance, field, options)
else
TokenAuthenticatableStrategies::Insecure.new(instance, field, options)
end
end
protected
def write_new_token(instance)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment