Created
October 19, 2017 06:41
-
-
Save noel9999/8f09bfa05e88b4b0d563a43c0717d6a7 to your computer and use it in GitHub Desktop.
惱人的動態字串
This file contains hidden or 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 tcat_delivery_list | |
@tcat_delivery_list or begin | |
delivery_option = DeliveryOption.valid.find_by(owner_type: 'Merchant', owner_id: merchant.id, region_type: 'tw_tcat') | |
return @tcat_delivery_list = TcatDeliveryList.new('tw_tcat', nil) if delivery_option.blank? | |
contract_code = delivery_option.config_data['contract_code'].tap { |code| raise "DeliveryOption #{delivery_option.id} has no contract_code" if code.blank? } | |
@tcat_delivery_list = TcatDeliveryList.new('tw_tcat', contract_code) | |
end | |
end | |
def tcat_pay_delivery_list | |
@tcat_pay_delivery_list or begin | |
delivery_option = DeliveryOption.valid.find_by(owner_type: 'Merchant', owner_id: merchant.id, region_type: 'tw_tcat_pay') | |
return @tcat_pay_delivery_list = TcatDeliveryList.new('tw_tcat_pay', nil) if delivery_option.blank? | |
contract_code = delivery_option.config_data['contract_code'].tap { |code| raise "DeliveryOption #{delivery_option.id} has no contract_code" if code.blank? } | |
@tcat_pay_delivery_list = TcatDeliveryList.new('tw_tcat_pay', contract_code) | |
end | |
end | |
%w(tcat tcat_pay).each do |type| | |
class_eval <<-RUBY, __FILE__, __LINE__ + 1 | |
def #{type}_delivery_list | |
@#{type}_delivery_list or begin | |
region_type = "tw_%s" % :#{type}.to_s | |
delivery_option = DeliveryOption.valid.find_by(owner_type: 'Merchant', owner_id: merchant.id, region_type: region_type) | |
return @#{type}_delivery_list = TcatDeliveryList.new(region_type, nil) if delivery_option.blank? | |
contract_code = delivery_option.config_data['contract_code'].tap { |code| raise "DeliveryOption %s has no contract_code" % delivery_option.id if code.blank? } | |
@#{type}_delivery_list = TcatDeliveryList.new(region_type, contract_code) | |
end | |
end | |
RUBY | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment