Class: Decidim::SettingsManifest::Attribute

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, AttributeObject::Model
Defined in:
lib/decidim/settings_manifest.rb

Overview

Semi-private: Attributes are an abstraction used by SettingsManifest to encapsulate behavior related to each individual settings field. Shouldn’t be used from the outside.

Constant Summary collapse

TYPES =
{
  boolean: { klass: Boolean, default: false },
  integer: { klass: Integer, default: 0 },
  string: { klass: String, 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 }
}.freeze

Constants included from AttributeObject::TypeMap

AttributeObject::TypeMap::Boolean, AttributeObject::TypeMap::Decimal

Instance Method Summary collapse

Methods included from AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#build_choicesObject



125
126
127
# File 'lib/decidim/settings_manifest.rb', line 125

def build_choices
  choices.try(:call) || choices
end

#default_valueObject



121
122
123
# File 'lib/decidim/settings_manifest.rb', line 121

def default_value
  default || TYPES[type][:default]
end

#readonly?(context) ⇒ Boolean

Returns:



129
130
131
# File 'lib/decidim/settings_manifest.rb', line 129

def readonly?(context)
  readonly&.call(context)
end

#type_classObject



117
118
119
# File 'lib/decidim/settings_manifest.rb', line 117

def type_class
  TYPES[type][:klass]
end