Class: Decidim::Initiatives::CurrentInitiative

Inherits:
Object
  • Object
show all
Includes:
InitiativeSlug
Defined in:
decidim-initiatives/app/constraints/decidim/initiatives/current_initiative.rb

Overview

This class infers the current initiative we are scoped to by looking at the request parameters and the organization in the request environment, and injects it into the environment.

Instance Method Summary collapse

Methods included from InitiativeSlug

#id_from_slug, #slug_from_id

Instance Method Details

#matches?(request) ⇒ Boolean

Public: Matches the request against an initiative and injects it

into the environment.

request - The request that holds the initiative relevant

information.

Returns a true if the request matched, false otherwise

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'decidim-initiatives/app/constraints/decidim/initiatives/current_initiative.rb', line 18

def matches?(request)
  env = request.env

  @organization = env["decidim.current_organization"]
  return false unless @organization

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