Skip to content

Instantly share code, notes, and snippets.

@americodls
Created February 17, 2015 00:17
Show Gist options
  • Save americodls/27c615af43822c402375 to your computer and use it in GitHub Desktop.
Save americodls/27c615af43822c402375 to your computer and use it in GitHub Desktop.
Interface proposal for ServiceObject/Interactor/UseCase on rails
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