Class: Decidim::CustomUserFields::Fields::GenericField

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/decidim/custom_user_fields/fields/generic_field.rb

Direct Known Subclasses

DateField, TextAreaField, TextField

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, options) ⇒ GenericField

Returns a new instance of GenericField.



11
12
13
14
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 11

def initialize(definition, options)
  @definition = definition
  @options = options
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



10
11
12
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 10

def definition
  @definition
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 10

def options
  @options
end

Instance Method Details

#class_nameObject



28
29
30
31
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 28

def class_name
  class_specifier = name.to_s.underscore
  "field field--#{type} field--#{class_specifier}"
end

#configure_form(_form) ⇒ Object

Raises:



16
17
18
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 16

def configure_form(_form)
  raise Error, "Configure Form is not implemented for #{definition.type} type"
end

#form_tag(_form) ⇒ Object

Raises:



24
25
26
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 24

def form_tag(_form)
  raise Error, "Form Tag is not implemented for #{definition.type} type"
end

#map_model(_form, _model_data) ⇒ Object

Raises:



20
21
22
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 20

def map_model(_form, _model_data)
  raise Error, "Map Model is not implemented for #{definition.type} type"
end

#required?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/decidim/custom_user_fields/fields/generic_field.rb', line 33

def required?
  options[:required].present? && options[:required]
end