Class: Groundskeeper::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/groundskeeper/middleware.rb,
lib/groundskeeper/middleware/path.rb,
lib/groundskeeper/middleware/header.rb,
lib/groundskeeper/middleware/parameter.rb,
lib/groundskeeper/middleware/subdomain.rb

Direct Known Subclasses

Header, Parameter, Path, Subdomain

Defined Under Namespace

Classes: Header, Parameter, Path, Subdomain

Constant Summary collapse

NAMESPACE_KEY =
"Groundskeeper-Namespace"
TENANT_KEY =
"Groundskeeper-Tenant"
MODEL_KEY =
:model
QUERY_KEY =
:query
DEFAULT_KEY =
:default
QUERY_DEFAULT =
->(model, slug) do
  model.find_by_slug(slug)
end

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
# File 'lib/groundskeeper/middleware.rb', line 12

def initialize(app, options = {})
  raise ArgumentError, "missing model" unless options.key?(model_key)

  @options = options
  @app = app
  @env = {}
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
# File 'lib/groundskeeper/middleware.rb', line 20

def call(env)
  @env = env
  env[namespace_key] = namespace
  env[tenant_key] = tenant
  @app.call(env)
end