module ConfiguredFacilityPrompter

Public Instance Methods

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

Private Instance Methods

prompt_for_configured_facility_id(allow_none) click to toggle source
# File lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb, line 11
def prompt_for_configured_facility_id(allow_none)
  if respond_to?(:third_party_id)
    result = get("services/third_parties/#{third_party_id}/service_definitions/#{service_definition_id}/configured_facilities")
  elsif respond_to?(:service_id)
    result = get("services/services/#{service_id}/service_definitions/#{service_definition_id}/configured_facilities")
  end

  (puts "No facilities have been configured for this service/third party. Cannot continue"; exit 1) if result.empty?

  # Build a menu of the services
  puts
  return prompter.choose do | menu |
    menu.prompt = "Select the Configured Facility: "
    menu.choice("No Selection") { -1 } if allow_none
    result.each do | configured_facility |
      menu.choice("#{configured_facility['facility_name']} (#{configured_facility['facility_id']}) - #{configured_facility['enabled']}") { configured_facility['id'] }
    end
  end
end