class Decidim::DecidimAwesome::ContextAnalyzers::ComponentAnalyzer

Translates a decidim component to detected participatory spaces and components

Attributes

component[R]
context[R]

Public Class Methods

context_for(component) click to toggle source
# File lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb, line 13
def self.context_for(component)
  analyzer = new component
  analyzer.extract_context!
  analyzer.context
end
new(component) click to toggle source
# File lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb, line 8
def initialize(component)
  @component = component
  @context = {}
end

Public Instance Methods

extract_context!() click to toggle source
# File lib/decidim/decidim_awesome/context_analyzers/component_analyzer.rb, line 21
def extract_context!
  if @component.respond_to? :participatory_space
    @context[:participatory_space_manifest] = @component.participatory_space.manifest.name.to_s
    @context[:participatory_space_slug] = @component.participatory_space&.slug
  end

  if @component.respond_to? :component
    @context[:component_manifest] = @component.component.manifest.name.to_s
    @context[:component_id] = @component.component&.id&.to_s
  elsif @component.is_a? Decidim::Component
    @context[:component_manifest] = @component.manifest.name.to_s
    @context[:component_id] = @component&.id&.to_s
  end
end