Class: Decidim::FeatureSettingsManifest
- Inherits:
-
Object
- Object
- Decidim::FeatureSettingsManifest
- Defined in:
- lib/decidim/features/settings_manifest.rb
Overview
This class serves as a DSL that enables specifying an arbitrary settings to a feature, so the admin panel can show a standarized UI to configure them.
Defined Under Namespace
Classes: Attribute
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#attribute(name, options = {}) ⇒ Object
Public: Adds a new attribute field to the FeatureSettingsManifest.
-
#initialize ⇒ FeatureSettingsManifest
constructor
Initializes a FeatureSettingsManifest.
-
#schema ⇒ Object
Public: Creates a model Class that sanitizes, coerces and filters data to the right types given a hash of serialized information.
Constructor Details
#initialize ⇒ FeatureSettingsManifest
Initializes a FeatureSettingsManifest.
11 12 13 |
# File 'lib/decidim/features/settings_manifest.rb', line 11 def initialize @attributes = {} end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/decidim/features/settings_manifest.rb', line 8 def attributes @attributes end |
Instance Method Details
#attribute(name, options = {}) ⇒ Object
Public: Adds a new attribute field to the FeatureSettingsManifest.
name - The name of the attribute to inject. options - A set of options to configure the attribute.
:type - The type of the attribute as found in Attribute::TYPES
:default - The default value of this settings field.
Returns nothing.
23 24 25 26 27 28 29 |
# File 'lib/decidim/features/settings_manifest.rb', line 23 def attribute(name, = {}) attribute = Attribute.new() attribute.validate! @attributes[name.to_sym] = attribute @schema = nil end |
#schema ⇒ Object
Public: Creates a model Class that sanitizes, coerces and filters data to the right types given a hash of serialized information.
Returns a Class.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/decidim/features/settings_manifest.rb', line 35 def schema return @schema if @schema manifest = self @schema = Class.new do include Virtus.model include ActiveModel::Validations cattr_accessor :manifest def self.model_name ActiveModel::Name.new(self, nil, "FeatureSettings") end def manifest self.class.manifest end def ==(other) other.attributes == attributes end manifest.attributes.each do |name, attribute| attribute name, attribute.type_class, default: attribute.default_value validates name, presence: true end end @schema.manifest = self @schema end |