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

Extract token authenticatable strategy fabrication

parent f1a74a65
...@@ -20,13 +20,8 @@ module TokenAuthenticatable ...@@ -20,13 +20,8 @@ module TokenAuthenticatable
attr_accessor :cleartext_tokens attr_accessor :cleartext_tokens
strategy = if options[:digest] strategy = TokenAuthenticatableStrategies::Base
TokenAuthenticatableStrategies::Digest.new(self, token_field, options) .fabricate(self, token_field, options)
elsif options[:encrypted]
TokenAuthenticatableStrategies::Encrypted.new(self, token_field, options)
else
TokenAuthenticatableStrategies::Insecure.new(self, token_field, options)
end
if unique if unique
define_singleton_method("find_by_#{token_field}") do |token| define_singleton_method("find_by_#{token_field}") do |token|
......
...@@ -43,6 +43,16 @@ module TokenAuthenticatableStrategies ...@@ -43,6 +43,16 @@ module TokenAuthenticatableStrategies
options[:fallback] == true options[:fallback] == true
end 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 protected
def write_new_token(instance) 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