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.



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

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



19
20
21
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 19

def context
  @context
end

#requestObject (readonly)

Returns the value of attribute request.



19
20
21
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 19

def request
  @request
end

Class Method Details

.context_for(request) ⇒ Object



13
14
15
16
17
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 13

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

Instance Method Details

#extract_context!Object



21
22
23
24
# File 'lib/decidim/decidim_awesome/context_analyzers/request_analyzer.rb', line 21

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