Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment