Class: Decidim::Feature

Inherits:
ApplicationRecord show all
Defined in:
app/models/decidim/feature.rb

Overview

A Feature represents a self-contained group of functionalities usually defined via a FeatureManifest and its Components. It’s meant to be able to provide a single feature that spans over several steps, each one with its component.

Instance Method Summary collapse

Instance Method Details

#manifestObject

Public: Finds the manifest this feature is associated to.

Returns a FeatureManifest.



21
22
23
# File 'app/models/decidim/feature.rb', line 21

def manifest
  Decidim.find_feature_manifest(manifest_name)
end

#manifest=(manifest) ⇒ Object

Public: Assigns a manifest to this feature.

manifest - The FeatureManifest for this Feature.

Returns nothing.



30
31
32
# File 'app/models/decidim/feature.rb', line 30

def manifest=(manifest)
  self.manifest_name = manifest.name
end

#settingsObject



34
35
36
# File 'app/models/decidim/feature.rb', line 34

def settings
  settings_schema(:global).new(self[:settings]["global"])
end

#settings=(data) ⇒ Object



38
39
40
# File 'app/models/decidim/feature.rb', line 38

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

#step_settingsObject



42
43
44
45
46
# File 'app/models/decidim/feature.rb', line 42

def step_settings
  participatory_process.steps.each_with_object({}) do |step, result|
    result[step.id.to_s] = settings_schema(:step).new(self[:settings].dig("steps", step.id.to_s))
  end
end

#step_settings=(data) ⇒ Object



48
49
50
51
52
# File 'app/models/decidim/feature.rb', line 48

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