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.1.0"
Instance Attribute Summary collapse
-
#external_domain ⇒ Object
readonly
Returns the value of attribute external_domain.
-
#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 |
# 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) 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 |
#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.
38 39 40 |
# File 'lib/publishing_platform_location.rb', line 38 def external_url_for(service, = {}) find(service, .merge(external: true)) end |
#find(service, options = {}) ⇒ Object
Find the base URL for a service/application.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/publishing_platform_location.rb', line 22 def find(service, = {}) name = valid_service_name(service) 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.
43 44 45 |
# File 'lib/publishing_platform_location.rb', line 43 def website_root env_var_or_fallback("PUBLISHING_PLATFORM_WEBSITE_ROOT") { find("www") } end |