publishing_platform_location 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77c35943b03cb4e040b83b274fd950ac14eda328a0931a72dc442897009bf38c
4
- data.tar.gz: 77a17a9950dc7ccef0db815343b06cc88ad45f7484c63e2344d6987de9c75847
3
+ metadata.gz: 8da954c6a842996e1f2370c2ed643ec42b622ec35310da7072a49543516d5d80
4
+ data.tar.gz: 4cb904a614d96f2618acd421796d14378f8160f429422d6abd967cca7cba6a62
5
5
  SHA512:
6
- metadata.gz: 17182fe6879038f28913b772f58700c20de117f891d0aeefd64b7b5d7e6bcb7d2d216b584b42f4740a5c348120c0276726ebb4e3f75451cea46632aba4ac5e43
7
- data.tar.gz: 605844317f619c688c4d2b7deb83501e88cb13b4cc5e6685a561d250a3c4a718adeaa2eeb3b8d0db4ca585f13fdf28e5e6b5b6ba721978445801ac4170ba550e
6
+ metadata.gz: aca0dfc3d388204cc20068b53f52f9af149ebbaa6f246f96b9b3ce4dc239dd91ffc032d8375020c81c886621be9008f4998b7e04f0a33c98650aedaec16e3c86
7
+ data.tar.gz: 3271cc714158443ec3bbc810c3d5bc6dcd3448811b5983ed271cd2183948722654a7f86edc631fcf6bc5f52ea9bfd50db285f83b062f8da337e675a3d2b67c2c
data/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # publishing_platform_location
1
+ # Publishing Platform Location
2
2
  Generates URLs for publishing platform services based on environment.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PublishingPlatformLocation
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -10,24 +10,25 @@ class PublishingPlatformLocation
10
10
  # The fallback parent domain to use in development mode.
11
11
  DEV_DOMAIN = "dev.publishing-platform.co.uk"
12
12
 
13
- attr_reader :parent_domain, :external_domain, :host_prefix
13
+ attr_reader :parent_domain, :external_domain
14
14
 
15
15
  # Construct a new PublishingPlatformLocation instance.
16
16
  def initialize(domain_to_use = nil, external_domain = nil)
17
17
  @parent_domain = domain_to_use || env_var_or_fallback("PUBLISHING_PLATFORM_APP_DOMAIN", DEV_DOMAIN) # empty string for internal services
18
18
  @external_domain = external_domain || ENV.fetch("PUBLISHING_PLATFORM_APP_DOMAIN_EXTERNAL", @parent_domain)
19
- @host_prefix = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_HOSTNAME_PREFIX", "")
19
+ @host_prefix = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_HOSTNAME_PREFIX", "")
20
+ @unprefixable_hosts = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_UNPREFIXABLE_HOSTS", "").split(",").map(&:strip)
20
21
  end
21
22
 
22
23
  # Find the base URL for a service/application.
23
24
  def find(service, options = {})
24
25
  name = valid_service_name(service)
25
26
 
26
- name = "#{host_prefix}#{name}"
27
-
28
27
  if (service_uri = defined_service_uri_for(name))
29
28
  return service_uri
30
- end
29
+ end
30
+
31
+ name = "#{host_prefix}#{name}" unless unprefixable_hosts.include?(name)
31
32
 
32
33
  domain = options[:external] ? external_domain : parent_domain
33
34
  domain_suffix = domain.empty? ? "" : ".#{domain}" # empty string for internal services
@@ -59,6 +60,8 @@ class PublishingPlatformLocation
59
60
 
60
61
  private
61
62
 
63
+ attr_reader :host_prefix, :unprefixable_hosts
64
+
62
65
  def valid_service_name(name)
63
66
  service_name = name.to_s
64
67
  return service_name if service_name.match?(/\A[a-z1-9.-]+\z/)
@@ -86,11 +89,11 @@ private
86
89
  # environment variable.
87
90
  #
88
91
  # e.g. if PUBLISHING_PLATFORM_LOCATION_SERVICE_CHEESE_THING_URI
89
- # was set, +PublishingPlatformLocation.new.find('cheese-thing')+
90
- # would return the value of that variable.
92
+ # was set, +PublishingPlatformLocation.new.find('cheese-thing')+
93
+ # would return the value of that variable.
91
94
  def defined_service_uri_for(service)
92
95
  service_name = service.upcase.tr("-", "_")
93
96
  uri = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_SERVICE_#{service_name}_URI", "")
94
97
  uri.empty? ? nil : uri
95
- end
98
+ end
96
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishing_platform_location
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Publishing Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control