class Socialmux::Strategy
Attributes
adapter[R]
current_user[R]
data[R]
user_params[R]
Public Class Methods
new(options)
click to toggle source
# File lib/socialmux/strategy.rb, line 11 def initialize(options) options.assert_valid_keys(:adapter, :current_user, :data, :user_params) options.each do |key, value| instance_variable_set "@#{key}", value end end
Public Instance Methods
result()
click to toggle source
# File lib/socialmux/strategy.rb, line 22 def result authentication_already_taken || returning_user || augmented_current_user || augmented_user_with_same_email || new_user end
Private Instance Methods
augment_user(user)
click to toggle source
# File lib/socialmux/strategy.rb, line 65 def augment_user(user) adapter.update_user_with_data_if_blank(user, data) adapter.update_user_with_params(user, user_params) adapter.build_authentication(user, data) user end
augmented_current_user()
click to toggle source
# File lib/socialmux/strategy.rb, line 44 def augmented_current_user return nil if !current_user augment_user(current_user) Result.new(current_user, Event::TOUCHED_CURRENT_USER) end
augmented_user_with_same_email()
click to toggle source
# File lib/socialmux/strategy.rb, line 51 def augmented_user_with_same_email user = adapter.find_user_with_email(data.email) return if !user augment_user(user) return Result.new(user, Event::TOUCHED_EMAIL_USER) end
authentication_already_taken()
click to toggle source
# File lib/socialmux/strategy.rb, line 32 def authentication_already_taken user = adapter.find_user_with_authentication(data) if current_user && user && current_user != user Result.new(nil, Event::AUTHENTICATION_ALREADY_TAKEN) end end
new_user()
click to toggle source
# File lib/socialmux/strategy.rb, line 59 def new_user user = adapter.init_user(data, user_params) augment_user(user) Result.new(user, Event::SIGN_UP) end
returning_user()
click to toggle source
# File lib/socialmux/strategy.rb, line 39 def returning_user user = adapter.find_user_with_authentication(data) Result.new(user, Event::SIGN_IN) if user end