is complex (e.g. closing the books at the end of an accounting period) ▸ The action reaches across multiple models (e.g. an e-commerce purchase using Order, CreditCard and Customer objects) ▸ The action interacts with an external service (e.g. posting to social networks) ▸ The action is not a core concern of the underlying model (e.g. sweeping up outdated data after a certain time period). ▸ There are multiple ways of performing the action (e.g. authenticating with an access token or password). This is the Gang of Four Strategy pattern.” http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
▸ Explicit ▸ Convenient bindings for Rails and Hanami ▸ Long-term support ▸ Premium support ▸ Steep learning curve ▸ A lot of dependencies ▸ Explicit ▸ Documentation could be improved CONS
hash :options do boolean :gift_wrapped end def execute order = credit_card.purchase(item) notify(credit_card.account) order end private def notify(account) # ... end end https://github.com/orgsync/active_interaction
= User.authenticate(context.email, context.password) context.user = user context.token = user.secret_token else context.fail!(message: "authenticate_user.failure") end end end https://github.com/collectiveidea/interactor
AuthenticateUser.call(session_params) if result.success? session[:user_token] = result.token redirect_to result.user else flash.now[:message] = t(result.message) render :new end end private def session_params params.require(:session).permit(:email, :password) end end https://github.com/collectiveidea/interactor