-
-
Save rosylilly/285ec33e6cfceb0ba0cf to your computer and use it in GitHub Desktop.
Where is Logics?
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 User | |
def buy_item(item) | |
self.purchases.create(item: item) | |
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 PurchasesController | |
def create | |
item = Item.find(params[:item_id]) | |
current_user.purchases.create(item: item) | |
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 BuyItemContext | |
def initialize(user, item) | |
@user = user | |
@item = item | |
@user.extend(Customer) | |
end | |
def process | |
@user.buy(item) | |
end | |
end | |
module Customer | |
def buy(item) | |
self.purchases.create(item: item) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment