Class: Decidim::DecidimAwesome::ContextAnalyzers::RequestAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb

Overview

Translates some Decidim URL path to detected participatory spaces and components

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestAnalyzer

Returns a new instance of RequestAnalyzer.



29
30
31
32
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 29

def initialize(request)
  @request = request
  @context = {}
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



34
35
36
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 34

def context
  @context
end

#requestObject (readonly)

Returns the value of attribute request.



34
35
36
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 34

def request
  @request
end

Class Method Details

.context_for(request) ⇒ Object



9
10
11
12
13
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 9

def context_for(request)
  analyzer = new request
  analyzer.extract_context!
  analyzer.context
end

.participatory_spaces_routesObject

In the frontend there’s no a 100% correspondence between url and manifest name



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 16

def participatory_spaces_routes
  spaces = Decidim.participatory_space_manifests \
                  .filter { |space| !DecidimAwesome.config.participatory_spaces_routes_context.has_key?(space.name) } \
                  .to_h { |space| [space.name.to_s, space.name.to_s] }
  DecidimAwesome.config.participatory_spaces_routes_context.each do |manifest, routes|
    routes.each do |route|
      spaces[route.to_s] = manifest.to_s
    end
  end
  spaces
end

Instance Method Details

#extract_context!Object



36
37
38
39
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 36

def extract_context!
  path = URI.parse(@request.url).path
  context_from_path path
end