Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vmoravec/4463296 to your computer and use it in GitHub Desktop.
Save vmoravec/4463296 to your computer and use it in GitHub Desktop.
# This is a possible approach to baking in side-effect free support into
# the context object for DCI. The #on_call would support a declarative way of
# knowing which roles to mixin/unmix on a given object. This could
# use something like mixology or another implementation under the covers.
class AddToCartContext < Context
attr_reader :user, :book
def self.call(user, book)
AddToCartContext.new(user, book).call
end
def initialize(user, book)
@user, @book = user, book
end
on_call :user => becomes(Customer) do
@user.add_to_cart, @book
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment