Class: Decidim::SettingsManifest::Attribute

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
decidim-core/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 },
  scope: { klass: Integer, default: nil },
  time: { klass: Time, default: nil }
}.freeze

Instance Method Summary collapse

Instance Method Details

#build_choicesObject


123
124
125
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 123

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

#default_valueObject


119
120
121
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 119

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

#readonly?(context) ⇒ Boolean

Returns:

  • (Boolean)

127
128
129
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 127

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

#type_classObject


115
116
117
# File 'decidim-core/lib/decidim/settings_manifest.rb', line 115

def type_class
  TYPES[type][:klass]
end