Sha256: 8d07252e60ef19a56ff3e2477de2edd4a502c844fa7fcde5f3255bd2b253f6e0

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

module ConfiguredFacilityPrompter

  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

  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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pvdgm-svc-client-0.3.4 lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb
pvdgm-svc-client-0.3.3 lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb
pvdgm-svc-client-0.3.2 lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb
pvdgm-svc-client-0.2.2 lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb
pvdgm-svc-client-0.2.1 lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb
pvdgm-svc-client-0.1.6 lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb