-
-
Save vmoravec/4463296 to your computer and use it in GitHub Desktop.
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
# 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