Class: Decidim::SettingsManifest::Attribute
Overview
Semi-private: Attributes are an abstraction used by SettingsManifest to encapsulate behavior related to each individual settings field. Should not be used from the outside.
Constant Summary
collapse
- TYPES =
{
boolean: { klass: Boolean, default: false },
integer: { klass: Integer, default: 0 },
integer_with_units: { klass: Decidim::Attributes::IntegerWithUnits, default: [5, "minutes"] },
string: { klass: String, default: nil },
float: { klass: Float, default: nil },
text: { klass: String, default: nil },
array: { klass: Array, default: [] },
enum: { klass: String, default: nil },
select: { klass: String, default: nil },
scope: { klass: Integer, default: nil },
time: { klass: Decidim::Attributes::TimeWithZone, default: nil },
taxonomy_filters: { klass: Array, default: [] }
}.freeze
AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal
Instance Method Summary
collapse
#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h
Instance Method Details
#build_choices(context = nil) ⇒ Object
158
159
160
|
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 158
def build_choices(context = nil)
choices.try(:call, context) || choices
end
|
#build_units ⇒ Object
162
163
164
|
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 162
def build_units
units.try(:call) || units
end
|
#default_value ⇒ Object
154
155
156
|
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 154
def default_value
default || TYPES[type][:default]
end
|
#editor?(context) ⇒ Boolean
170
171
172
173
174
|
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 170
def editor?(context)
return editor.call(context) if editor.respond_to?(:call)
editor
end
|
#readonly?(context) ⇒ Boolean
166
167
168
|
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 166
def readonly?(context)
readonly&.call(context)
end
|
#type_class ⇒ Object
148
149
150
151
152
|
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 148
def type_class
return Decidim::Attributes::RichText if type == :text && editor == true
TYPES[type][:klass]
end
|
#validate_integer_with_units_structure ⇒ Object
139
140
141
142
143
144
145
146
|
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 139
def validate_integer_with_units_structure
return unless type == :integer_with_units
errors.add(:default, :invalid) unless default_value.is_a?(::Array) &&
default_value.size == 2 &&
default_value[0].is_a?(Integer) &&
build_units.include?(default_value[1])
end
|