Module: NurseAndrea::PlatformDetector
- Defined in:
- lib/nurse_andrea/platform_detector.rb
Constant Summary collapse
- PLATFORMS =
{ railway: -> { ENV.key?("RAILWAY_ENVIRONMENT") }, render: -> { ENV.key?("RENDER") }, fly: -> { ENV.key?("FLY_APP_NAME") }, heroku: -> { ENV.key?("DYNO") }, digitalocean: -> { ENV.key?("DIGITALOCEAN_APP_PLATFORM_COMPONENT_NAME") }, vercel: -> { ENV.key?("VERCEL") }, }.freeze
Class Method Summary collapse
Class Method Details
.context ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nurse_andrea/platform_detector.rb', line 21 def self.context platform = detect ctx = { platform: platform } case platform when "railway" ctx[:region] = ENV["RAILWAY_REGION"] if ENV.key?("RAILWAY_REGION") ctx[:environment] = ENV["RAILWAY_ENVIRONMENT"] if ENV.key?("RAILWAY_ENVIRONMENT") when "render" ctx[:region] = ENV["RENDER_REGION"] if ENV.key?("RENDER_REGION") when "fly" ctx[:region] = ENV["FLY_REGION"] if ENV.key?("FLY_REGION") when "heroku" ctx[:dyno_type] = ENV["DYNO"]&.gsub(/\.\d+$/, "") if ENV.key?("DYNO") end ctx end |
.detect ⇒ Object
16 17 18 19 |
# File 'lib/nurse_andrea/platform_detector.rb', line 16 def self.detect PLATFORMS.each { |name, check| return name.to_s if check.call } "unknown" end |