Module: Restless::Env
- Defined in:
- lib/restless/env.rb
Overview
Environment probing: CONFIG-003, CONFIG-004, BATCH-003, BATCH-008.
All of it is per-language by design (CONTRACT.md section 14); what is normative is only the effect.
Constant Summary collapse
- DEFAULT_BASE_URL =
WIRE-005.
"https://ingress.restless.ai"
Class Method Summary collapse
-
.app_env ⇒ Object
BATCH-003's "language equivalent environment indicator".
-
.debug? ⇒ Boolean
CONFIG-004.
- .debug_log(message) ⇒ Object
- .localhost?(base_url) ⇒ Boolean
- .production? ⇒ Boolean
-
.resolve_api_key(explicit = nil) ⇒ Object
CONFIG-001.
-
.resolve_base_url(explicit = nil) ⇒ Object
CONFIG-003.
- .setup_mode? ⇒ Boolean
-
.test_run? ⇒ Boolean
BATCH-008.
Class Method Details
.app_env ⇒ Object
BATCH-003's "language equivalent environment indicator". Ruby has three spellings in the wild and no single winner, so all three are consulted, most specific first.
17 18 19 20 21 22 23 |
# File 'lib/restless/env.rb', line 17 def app_env %w[RESTLESS_ENV RACK_ENV RAILS_ENV].each do |name| value = ENV[name] return value if value && !value.empty? end "" end |
.debug? ⇒ Boolean
CONFIG-004. DEBUG containing restless as a whitespace- or
comma-delimited token, or the literal *.
51 52 53 54 55 56 |
# File 'lib/restless/env.rb', line 51 def debug? flag = ENV["DEBUG"].to_s return true if flag == "*" || flag == "restless" flag.split(/[\s,]+/).include?("restless") end |
.debug_log(message) ⇒ Object
58 59 60 |
# File 'lib/restless/env.rb', line 58 def debug_log() warn("[restless] #{}") if debug? end |
.localhost?(base_url) ⇒ Boolean
78 79 80 |
# File 'lib/restless/env.rb', line 78 def localhost?(base_url) base_url.include?("//localhost") || base_url.include?("//127.0.0.1") end |
.production? ⇒ Boolean
25 26 27 |
# File 'lib/restless/env.rb', line 25 def production? app_env == "production" end |
.resolve_api_key(explicit = nil) ⇒ Object
CONFIG-001. Explicit key, then RESTLESS_KEY, then README_API_KEY.
63 64 65 66 |
# File 'lib/restless/env.rb', line 63 def resolve_api_key(explicit = nil) [explicit, ENV["RESTLESS_KEY"], ENV["README_API_KEY"]] .find { |v| v && !v.empty? } || "" end |
.resolve_base_url(explicit = nil) ⇒ Object
CONFIG-003.
69 70 71 72 73 74 75 76 |
# File 'lib/restless/env.rb', line 69 def resolve_base_url(explicit = nil) return explicit if explicit && !explicit.empty? from_env = ENV["RESTLESS_BASE_URL"] return from_env if from_env && !from_env.empty? DEFAULT_BASE_URL end |
.setup_mode? ⇒ Boolean
45 46 47 |
# File 'lib/restless/env.rb', line 45 def setup_mode? ENV["RESTLESS_SETUP_MODE"] == "1" end |
.test_run? ⇒ Boolean
BATCH-008. Under a test runner, captures are dropped rather than uploaded, unless RESTLESS_SETUP_MODE=1. Test suites must not hammer production ingest.
The constants are checked rather than merely defined?(Minitest) at the
top level, because a library can pull minitest in without the process
actually being a test run.
36 37 38 39 40 41 42 43 |
# File 'lib/restless/env.rb', line 36 def test_run? return true if app_env == "test" return true if defined?(::RSpec::Core) return true if defined?(::Minitest::Test) return true if defined?(::Test::Unit::TestCase) false end |