Sha256: 4321fe093078106a0ede2df7009c0e699c9263917d7def14e57d8e307db1a7ca

Contents?: true

Size: 916 Bytes

Versions: 3

Compression:

Stored size: 916 Bytes

Contents

module UserMappingPrompter

  def user_mapping_id(allow_none=false)
    return options[:user_mapping_id] if options[:user_mapping_id]
    return options[:user_mapping_id] = ENV['USER_MAPPING_ID'] if ENV['USER_MAPPING_ID']
    return options[:user_mapping_id] = prompt_for_user_mapping_id(allow_none)
  end

  private

  def prompt_for_user_mapping_id(allow_none)
    result = get("services/third_parties/#{third_party_id}/user_mappings")

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

    # Build a menu of the user mappings
    puts
    return prompter.choose do | menu |
      menu.prompt = "Select the User Mapping: "
      menu.choice("No Selection") { -1 } if allow_none
      result.each do | user_mapping |
        menu.choice("#{user_mapping['user_name']} (#{user_mapping['user_id']}) - #{user_mapping['user_code']}") { user_mapping['id'] }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pvdgm-svc-client-0.3.4 lib/pvdgm-svc-client/prompters/user_mapping_prompter.rb
pvdgm-svc-client-0.3.3 lib/pvdgm-svc-client/prompters/user_mapping_prompter.rb
pvdgm-svc-client-0.3.2 lib/pvdgm-svc-client/prompters/user_mapping_prompter.rb