Created
April 17, 2014 22:06
-
-
Save thatrubylove/11014259 to your computer and use it in GitHub Desktop.
an-exercise-in-refactoring-large-methods-in-ruby-example-3
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
def update | |
render params[:credit_card].present? ? process_order(params) : | |
create_shipping_contact(params) | |
end | |
def process_order(params) | |
response = @order.process(params) | |
response[:status] == "success" ? { template: "orders/show" } : | |
{ json: response } | |
end | |
def create_shipping_contact(params) | |
if has_ship_options?(params) | |
@order.create_shipping_contact(params[:shipping_contact], | |
params[:shipping_address]) | |
end | |
{ template: "orders/show" } | |
end | |
def has_ship_options?(params) | |
params[:shipping_contact].present? && | |
params[:shipping_address].present? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment