-
-
Save fxposter/9995722 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
class Product < ActiveRecord::Base | |
end | |
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 ProductController < ApplicationController | |
# ... | |
def create | |
creates_product = CreatesProduct.new(Product, global_or_new_publisher) | |
product = creates_product.call(product_params) | |
# ... | |
end | |
end |
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 CreatesProduct | |
def initialize(factory, events) | |
@factory = factory | |
@events = events | |
end | |
def call(product_params) | |
product = @factory.new(product_params) | |
# do domething | |
@events.broadcast(:before_save, product) | |
# do domething | |
result = product.save | |
# do domething | |
@events.broadcast(:after_save, product, result) | |
# do domething | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment