Created
April 21, 2015 22:01
-
-
Save laserlemon/71eff42b27e496db2a4f to your computer and use it in GitHub Desktop.
Proposed Interactor 4.0 Syntax
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 PlaceOrder | |
include Interactor | |
# What goes here? | |
before do | |
context.user ||= User.find(context.user_id) | |
end | |
def call | |
context.order = context.user.orders.create(context.attributes) | |
context.fail! unless context.order.persisted? | |
end | |
end |
Heck, I'd even like to do away with the call
and any reference to context
and replace it with something like:
fails_on(error: "Order not persisted") { !order.persisted? }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMO the following is easier to read and reason about, but that may just my bias since I've been thinking along these lines recently: