# Use service object when: # 1- The action is complex. # 2- The action reaches across multiple models. # 3- The action interacts with an external service (e.g. posting to social networks) # 4- The action is not a core concern of the underlying model (e.g. sweeping up outdated data after a certain time period). # 5- There are multiple ways of performing the action (e.g. authenticating with an access token or password). class Authentication def initialize(params, omniauth = nil) @params = params @omniauth = omniauth end def user @user = @omniauth ? user_from_omniauth : user_with_password end def authenticated? user.present? end private def user_from_omniauth # Authenticate with omniauth end def user_with_password # Authenticate with password end end