Skip to content

Instantly share code, notes, and snippets.

@igor-alexandrov
Created October 7, 2014 07:57
Show Gist options
  • Save igor-alexandrov/19d6ca0a28f2059117dd to your computer and use it in GitHub Desktop.
Save igor-alexandrov/19d6ca0a28f2059117dd to your computer and use it in GitHub Desktop.
@purchased_at = Date.civil(params[:purchased_at]["(1i)"].to_i,
params[:purchased_at]["(2i)"].to_i,
params[:purchased_at]["(3i)"].to_i)
@code = Partner::Code.lookup("Vendor", params[:code]) || build_vendor_code
@not_redeem = nil
@error_text = nil
@to_late = nil
if @code.nil?
@not_redeem = true
@error_text = I18n.t("fc.check_all_fields")
elsif @purchased_at >= Date.parse("01/07/2014")
@to_late = true
@error_text = I18n.t('fc.to_late')
elsif @code.new_record?
if @code.save
@error_text = I18n.t("fc.receipt_sent")
@not_redeem = true
else
@not_redeem = true
@error_text = I18n.t("fc.receipt_is_not_sent")
end
elsif @code.not_confirmed?
@not_redeem = true
@error_text = I18n.t("fc.receipt_already_sent")
elsif @code.confirmed?
order = Paysteps::Order.new
order.payable = @code.payable
order.payer = current_user
@error_text = I18n.t("fc.already_bought") unless @code.payable.can_be_bought_with?(order)
elsif @code.redeemed?
@not_redeem = true
@error_text = I18n.t("fc.already_redeemed")
end
@GarPit
Copy link

GarPit commented Oct 7, 2014

Во, отличный пример для рефакторинга. Прям как у Sandi был на конфе)

@aishek
Copy link

aishek commented Oct 7, 2014

как-то маловато переменных экземпляра класса :)

@tanraya
Copy link

tanraya commented Oct 7, 2014

Игорь, покажи потом как зарефакторил.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment