Module: Decidim::HasSettings

Extended by:
ActiveSupport::Concern
Included in:
Component
Defined in:
lib/decidim/has_settings.rb

Instance Method Summary collapse

Instance Method Details

#current_settingsObject



29
30
31
32
33
34
35
# File 'lib/decidim/has_settings.rb', line 29

def current_settings
  if participatory_space.allows_steps?
    active_step_settings
  else
    default_step_settings
  end
end

#default_step_settingsObject



37
38
39
# File 'lib/decidim/has_settings.rb', line 37

def default_step_settings
  new_settings_schema(:step, self[:settings]["default_step"])
end

#default_step_settings=(data) ⇒ Object



41
42
43
# File 'lib/decidim/has_settings.rb', line 41

def default_step_settings=(data)
  self[:settings]["default_step"] = new_settings_schema(:step, data)
end

#settingsObject



21
22
23
# File 'lib/decidim/has_settings.rb', line 21

def settings
  new_settings_schema(:global, self[:settings]["global"])
end

#settings=(data) ⇒ Object



25
26
27
# File 'lib/decidim/has_settings.rb', line 25

def settings=(data)
  self[:settings]["global"] = new_settings_schema(:global, data)
end

#step_settingsObject



45
46
47
48
49
50
51
# File 'lib/decidim/has_settings.rb', line 45

def step_settings
  return {} unless participatory_space.allows_steps?

  participatory_space.steps.each_with_object({}) do |step, result|
    result[step.id.to_s] = new_settings_schema(:step, self[:settings].dig("steps", step.id.to_s))
  end
end

#step_settings=(data) ⇒ Object



53
54
55
56
57
# File 'lib/decidim/has_settings.rb', line 53

def step_settings=(data)
  self[:settings]["steps"] = data.each_with_object({}) do |(key, value), result|
    result[key.to_s] = new_settings_schema(:step, value)
  end
end