Module: Copse::UrlOptions
- Defined in:
- lib/copse/url_options.rb
Overview
Decides whether Copse should set default_url_options, and to what.
Deliberately Rails-free so every guard can be tested without booting an application -- which matters because only one Rails::Application can be initialized per process.
Class Method Summary collapse
-
.apply?(env: ENV, rails_env:, existing_host: nil) ⇒ Boolean
Copse only speaks up when all three are true: * this is development, * the app was actually booted by Copse (COPSE_URL is present), and * the app has not already set its own host.
-
.for(env: ENV) ⇒ Object
The options to merge.
- .url(env: ENV) ⇒ Object
Class Method Details
.apply?(env: ENV, rails_env:, existing_host: nil) ⇒ Boolean
Copse only speaks up when all three are true:
* this is development,
* the app was actually booted by Copse (COPSE_URL is present), and
* the app has not already set its own host.
A plain bin/rails server, any other environment, and any app with explicit
URL options are all left alone.
17 18 19 20 21 22 23 |
# File 'lib/copse/url_options.rb', line 17 def self.apply?(env: ENV, rails_env:, existing_host: nil) return false unless rails_env.to_s == "development" return false if env["COPSE_URL"].to_s.empty? return false unless existing_host.to_s.empty? true end |
.for(env: ENV) ⇒ Object
The options to merge. Prefers COPSE_PORT over PORT: under foreman, PORT is rewritten per child, while COPSE_PORT always carries the derived port.
27 28 29 30 31 32 |
# File 'lib/copse/url_options.rb', line 27 def self.for(env: ENV) = { host: env["COPSE_HOST"] } port = env["COPSE_PORT"] || env["PORT"] [:port] = Integer(port, exception: false) unless port.to_s.empty? .compact end |
.url(env: ENV) ⇒ Object
34 35 36 |
# File 'lib/copse/url_options.rb', line 34 def self.url(env: ENV) env["COPSE_URL"] end |