Class: Decidim::CurrentComponent

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/app/constraints/decidim/current_component.rb

Overview

This class infers the current component we're scoped to by looking at the request parameters and injects it into the environment.

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ CurrentComponent

Public: Initializes the class.

manifest - The manifest of the component to check against.


10
11
12
# File 'decidim-core/app/constraints/decidim/current_component.rb', line 10

def initialize(manifest)
  @manifest = manifest
end

Instance Method Details

#matches?(request) ⇒ Boolean

Public: Matches the request against a component and injects it into the

environment.

request - The request that holds the current component relevant information.

Returns a true if the request matched, false otherwise

Returns:

  • (Boolean)

20
21
22
23
24
25
26
27
# File 'decidim-core/app/constraints/decidim/current_component.rb', line 20

def matches?(request)
  env = request.env

  @participatory_space = env["decidim.current_participatory_space"]
  return false unless @participatory_space

  current_component(env, request.params) ? true : false
end