module AccountMappingPrompter

Public Instance Methods

account_mapping_id(allow_none=false) click to toggle source
# File lib/pvdgm-svc-client/prompters/account_mapping_prompter.rb, line 3
def account_mapping_id(allow_none=false)
  return options[:account_mapping_id] if options[:account_mapping_id]
  return options[:account_mapping_id] = ENV['ACCOUNT_MAPPING_ID'] if ENV['ACCOUNT_MAPPING_ID']
  return options[:account_mapping_id] = prompt_for_account_mapping_id(allow_none)
end

Private Instance Methods

prompt_for_account_mapping_id(allow_none) click to toggle source
# File lib/pvdgm-svc-client/prompters/account_mapping_prompter.rb, line 11
def prompt_for_account_mapping_id(allow_none)
  result = get("services/third_parties/#{third_party_id}/account_mappings")

  (puts "No third-parties are defined. Cannot continue"; exit 1) if result.empty?

  # Build a menu of the account mappings
  puts
  return prompter.choose do | menu |
    menu.prompt = "Select the Account Mapping: "
    menu.choice("No Selection") { -1 } if allow_none
    result.each do | account_mapping |
      menu.choice("#{account_mapping['account_name']} (#{account_mapping['account_id']}) - #{account_mapping['account_code']}") { account_mapping['id'] }
    end
  end
end