Class: Decidim::Toggle::ModuleConfigurationPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/toggle/module_configuration_presenter.rb

Overview

Read model around a Form built from stored JSON: normalizes nil for array/hash/boolean attributes so runtime code can use enabled?, empty collections, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ ModuleConfigurationPresenter

Returns a new instance of ModuleConfigurationPresenter.



8
9
10
11
# File 'lib/decidim/toggle/module_configuration_presenter.rb', line 8

def initialize(form)
  @form = form
  define_accessors!
end

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



13
14
15
# File 'lib/decidim/toggle/module_configuration_presenter.rb', line 13

def form
  @form
end

Instance Method Details

#to_config_hashObject



15
16
17
18
19
20
21
22
# File 'lib/decidim/toggle/module_configuration_presenter.rb', line 15

def to_config_hash
  @form.class.attribute_names.each_with_object({}) do |attr, hash|
    next if attr == "id"

    type = @form.class.attribute_types[attr]
    hash[attr] = normalize(@form.public_send(attr), attr, type)
  end
end