Class: Decidim::TermCustomizer::Context::JobContext

Inherits:
Base
  • Object
show all
Defined in:
lib/decidim/term_customizer/context/job_context.rb

Instance Attribute Summary

Attributes inherited from Base

#component, #organization, #space

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Decidim::TermCustomizer::Context::Base

Instance Method Details

#resolve!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/decidim/term_customizer/context/job_context.rb', line 7

def resolve!
  # Figure out the organization and user through the job arguments if
  # passed for the job.
  user = nil
  data[:job].arguments.each do |arg|
    @organization ||= organization_from_argument(arg)
    @space ||= space_from_argument(arg)
    @component ||= component_from_argument(arg)
    user ||= arg if arg.is_a?(Decidim::User)
  end

  # In case a component was found, define the space as the component
  # space to avoid any conflicts.
  @space = component.participatory_space if component

  # In case a space was found, define the organization as the space
  # organization to avoid any conflicts.
  @organization = space.organization if space

  # In case an organization could not be resolved any other way, check
  # it through the user (if the user was passed).
  @organization ||= user.organization if user
end