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. Should not be used from the outside.

Constant Summary collapse

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



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

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

#default_valueObject



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

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

#editor?(context) ⇒ Boolean

Returns:



134
135
136
137
138
# File 'lib/decidim/settings_manifest.rb', line 134

def editor?(context)
  return editor.call(context) if editor.respond_to?(:call)

  editor
end

#readonly?(context) ⇒ Boolean

Returns:



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

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

#type_classObject



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

def type_class
  TYPES[type][:klass]
end