Class: Decidim::Middleware::CurrentOrganization
- Inherits:
-
Object
- Object
- Decidim::Middleware::CurrentOrganization
- Defined in:
- lib/decidim/middleware/current_organization.rb
Overview
A middleware that enhances the request with the current organization based on the hostname.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Main entry point for a Rack Middleware.
-
#initialize(app) ⇒ CurrentOrganization
constructor
Initializes the Rack Middleware.
Constructor Details
#initialize(app) ⇒ CurrentOrganization
Initializes the Rack Middleware.
app - The Rack application
11 12 13 |
# File 'lib/decidim/middleware/current_organization.rb', line 11 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Main entry point for a Rack Middleware.
env - A Hash.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/decidim/middleware/current_organization.rb', line 18 def call(env) organization = detect_current_organization(env) if organization env["decidim.current_organization"] = organization @app.call(env) else organization = find_secondary_host_org(env) return @app.call(env) unless organization location = new_location_for(env, organization.host) [301, { "Location" => location, "Content-Type" => "text/html", "Content-Length" => "0" }, []] end end |