Created
December 17, 2014 07:33
-
-
Save sajoku/a2b90bcc8dea8fe69262 to your computer and use it in GitHub Desktop.
This is a sample order_syncer which syncs externals and needs the output of what is being synced in the next method.
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 OrderSyncer | |
def initialize(order) | |
@order = order | |
end | |
def synchronise_all | |
external_order_id = synchronise_order(@order) | |
external_payment_id = synchronise_payment(external_order_id) | |
external_contract_id = synchronise_contract(external_payment_id) | |
synchronise_authorisisation(external_contract_id) | |
end | |
private | |
def synchronise_order(order) | |
# If the fetcher does not return an order_id we need to synchronise | |
unless order_id = Fetcher::OrderId.new(order.id).fetch | |
order_id = Synchroniser::Order.new(order).synchronise | |
end | |
end | |
def synchronise_payment(external_order_id) | |
#Same kind of steps as in synchronise order | |
end | |
def synchronise_contract(external_payment_id) | |
#Same kind of steps as in synchronise order | |
end | |
def synchronise_authorisisation(external_contract_id) | |
#last step which always synchronises and returns an id or nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problems with this setup (imo):
Solutions I thought of but fear will overcomplicate the actual code:
SynchroniseOrder
which will Fetch OR Synchronise the order. Although this will make theOrderSynchroniser
class smaller now I have 3 separate classes that are being called.synchronise_method
s are all alike I thought about creating a more generic method which will be called with the classes it needs to call, making the setup some what more abstract and generic. I'm not sure this would be a step in the right direction since I'm afraid that it will make the code to abstract and hard to change in the future.