Module: Heatwave::AppType
- Defined in:
- lib/heatwave/app_type.rb
Constant Summary collapse
- TYPES =
%i[www crm api mcp media unknown].freeze
Class Method Summary collapse
- .api? ⇒ Boolean
- .crm? ⇒ Boolean
-
.current ⇒ Object
Thread-local storage for current request's app type Set by middleware early in the stack, read by controllers/services.
- .current=(type) ⇒ Object
-
.detect_from_host(host) ⇒ Object
Detect app type from host string Extracted for testability.
-
.from_request(env) ⇒ Object
Detect app type from Rack env (request) This is the primary detection method used by middleware.
-
.mcp? ⇒ Boolean
Check if current request is for a specific app type.
- .media? ⇒ Boolean
-
.run_for?(env, *included_types) ⇒ Boolean
For middleware that should only run on certain app types Returns true if the middleware should run.
-
.skip_for?(env, *excluded_types) ⇒ Boolean
For middleware that should only run on certain app types Returns true if the middleware should be skipped.
- .www? ⇒ Boolean
Class Method Details
.api? ⇒ Boolean
66 67 68 |
# File 'lib/heatwave/app_type.rb', line 66 def self.api? current == :api end |
.crm? ⇒ Boolean
70 71 72 |
# File 'lib/heatwave/app_type.rb', line 70 def self.crm? current == :crm end |
.current ⇒ Object
Thread-local storage for current request's app type
Set by middleware early in the stack, read by controllers/services
24 25 26 |
# File 'lib/heatwave/app_type.rb', line 24 def self.current RequestStore.store[:heatwave_app_type] || :unknown end |
.current=(type) ⇒ Object
28 29 30 |
# File 'lib/heatwave/app_type.rb', line 28 def self.current=(type) RequestStore.store[:heatwave_app_type] = type end |
.detect_from_host(host) ⇒ Object
Detect app type from host string
Extracted for testability
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/heatwave/app_type.rb', line 41 def self.detect_from_host(host) return :unknown if host.blank? subdomain = host.split('.').first&.downcase case subdomain when 'mcp' :mcp when 'api' :api when 'crm' :crm when 'media' :media else # Handle www subdomain, no subdomain (warmlyyours.com), or unknown subdomains :www end end |
.from_request(env) ⇒ Object
Detect app type from Rack env (request)
This is the primary detection method used by middleware
34 35 36 37 |
# File 'lib/heatwave/app_type.rb', line 34 def self.from_request(env) host = extract_host(env) detect_from_host(host) end |
.mcp? ⇒ Boolean
Check if current request is for a specific app type
62 63 64 |
# File 'lib/heatwave/app_type.rb', line 62 def self.mcp? current == :mcp end |
.media? ⇒ Boolean
78 79 80 |
# File 'lib/heatwave/app_type.rb', line 78 def self.media? current == :media end |
.run_for?(env, *included_types) ⇒ Boolean
For middleware that should only run on certain app types
Returns true if the middleware should run
91 92 93 94 |
# File 'lib/heatwave/app_type.rb', line 91 def self.run_for?(env, *included_types) app_type = from_request(env) included_types.include?(app_type) end |
.skip_for?(env, *excluded_types) ⇒ Boolean
For middleware that should only run on certain app types
Returns true if the middleware should be skipped
84 85 86 87 |
# File 'lib/heatwave/app_type.rb', line 84 def self.skip_for?(env, *excluded_types) app_type = from_request(env) excluded_types.include?(app_type) end |
.www? ⇒ Boolean
74 75 76 |
# File 'lib/heatwave/app_type.rb', line 74 def self.www? current == :www end |