Class: PublishingPlatformLocation
- Inherits:
-
Object
- Object
- PublishingPlatformLocation
- Extended by:
- Forwardable
- Defined in:
- lib/publishing_platform_location.rb,
lib/publishing_platform_location/version.rb
Defined Under Namespace
Classes: NoConfigurationError
Constant Summary collapse
- DEV_DOMAIN =
The fallback parent domain to use in development mode.
"dev.publishing-platform.co.uk"- VERSION =
"0.2.0"
Instance Attribute Summary collapse
-
#external_domain ⇒ Object
readonly
Returns the value of attribute external_domain.
-
#host_prefix ⇒ Object
readonly
Returns the value of attribute host_prefix.
-
#parent_domain ⇒ Object
readonly
Returns the value of attribute parent_domain.
Instance Method Summary collapse
-
#external_url_for(service, options = {}) ⇒ Object
Find the external URL for a service/application.
-
#find(service, options = {}) ⇒ Object
Find the base URL for a service/application.
-
#initialize(domain_to_use = nil, external_domain = nil) ⇒ PublishingPlatformLocation
constructor
Construct a new PublishingPlatformLocation instance.
-
#website_root ⇒ Object
Find the base URL for the public website frontend.
Constructor Details
#initialize(domain_to_use = nil, external_domain = nil) ⇒ PublishingPlatformLocation
Construct a new PublishingPlatformLocation instance.
16 17 18 19 20 |
# File 'lib/publishing_platform_location.rb', line 16 def initialize(domain_to_use = nil, external_domain = nil) @parent_domain = domain_to_use || env_var_or_fallback("PUBLISHING_PLATFORM_APP_DOMAIN", DEV_DOMAIN) # empty string for internal services @external_domain = external_domain || ENV.fetch("PUBLISHING_PLATFORM_APP_DOMAIN_EXTERNAL", @parent_domain) @host_prefix = ENV.fetch("PUBLISHING_PLATFORM_LOCATION_HOSTNAME_PREFIX", "") end |
Instance Attribute Details
#external_domain ⇒ Object (readonly)
Returns the value of attribute external_domain.
13 14 15 |
# File 'lib/publishing_platform_location.rb', line 13 def external_domain @external_domain end |
#host_prefix ⇒ Object (readonly)
Returns the value of attribute host_prefix.
13 14 15 |
# File 'lib/publishing_platform_location.rb', line 13 def host_prefix @host_prefix end |
#parent_domain ⇒ Object (readonly)
Returns the value of attribute parent_domain.
13 14 15 |
# File 'lib/publishing_platform_location.rb', line 13 def parent_domain @parent_domain end |
Instance Method Details
#external_url_for(service, options = {}) ⇒ Object
Find the external URL for a service/application.
45 46 47 |
# File 'lib/publishing_platform_location.rb', line 45 def external_url_for(service, = {}) find(service, .merge(external: true)) end |
#find(service, options = {}) ⇒ Object
Find the base URL for a service/application.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/publishing_platform_location.rb', line 23 def find(service, = {}) name = valid_service_name(service) name = "#{host_prefix}#{name}" if (service_uri = defined_service_uri_for(name)) return service_uri end domain = [:external] ? external_domain : parent_domain domain_suffix = domain.empty? ? "" : ".#{domain}" # empty string for internal services scheme = if [:force_http] || http_domain?(domain) "http:" else "https:" end "#{scheme}//#{name}#{domain_suffix}".freeze end |
#website_root ⇒ Object
Find the base URL for the public website frontend.
50 51 52 |
# File 'lib/publishing_platform_location.rb', line 50 def website_root env_var_or_fallback("PUBLISHING_PLATFORM_WEBSITE_ROOT") { find("www") } end |