Created
February 17, 2015 00:17
-
-
Save americodls/27c615af43822c402375 to your computer and use it in GitHub Desktop.
Interface proposal for ServiceObject/Interactor/UseCase on rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
def create | |
ToDoList::SignIn.new(sign_in_params).call({ | |
success: ->(message) { redirect_to dashboard_user_path, notice: t(message) }, | |
failure: ->(message) { render :new, error: t(message) } | |
}) | |
end | |
end | |
module ToDoList | |
class SignIn | |
def initialize(params) | |
@username, @password = params[:username], params[:password] | |
end | |
def call(callbacks) | |
if user && user.authentic?(password) | |
callbacks.fetch(:success).call("sign_in.success") | |
else | |
callbacks.fetch(:failure).call("sign_in.failure") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment