Skip to content

Instantly share code, notes, and snippets.

@zdennis
Created February 4, 2012 16:59
Show Gist options
  • Save zdennis/1738934 to your computer and use it in GitHub Desktop.
Save zdennis/1738934 to your computer and use it in GitHub Desktop.
Possible attempt at making side-effect DCI in ruby: http://mikepackdev.com/blog_posts/24-the-right-way-to-code-dci-in-ruby
# 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