-
-
Save PerezIgnacio/f9eb9b8b9cf243453abc909839f843a0 to your computer and use it in GitHub Desktop.
User Concern example
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
module Chargeable | |
extend ActiveSupport::Concern | |
def charge_order(amount, discount, products) | |
create_order(amount, discount, products) | |
send_order_charge | |
# ... | |
end | |
private | |
def create_order(amount, discount, products) | |
# altough we could pass the user as parameter, this concern incorrectly | |
# assumes that the user model includes the concern, an implicitness we should avoid | |
@order = Order.create!(amount: amount, discount: discount, products: products, user: self) | |
end | |
def send_order_charge | |
# logic related to payment process, usually calling an external API | |
end | |
# ... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment