Class: Bureaucrat::Fields::BooleanField

Inherits:
Field
  • Object
show all
Defined in:
lib/bureaucrat/fields.rb

Overview

URLField

Direct Known Subclasses

NullBooleanField

Instance Attribute Summary

Attributes inherited from Field

#error_messages, #help_text, #hidden_widget, #initial, #label, #required, #show_hidden_initial, #validators, #widget

Instance Method Summary collapse

Methods inherited from Field

#bound_data, #clean, #default_error_messages, #default_hidden_widget, #default_validators, #initialize, #initialize_copy, #populate_object, #prepare_value, #run_validators, #validate, #widget_attrs

Constructor Details

This class inherits a constructor from Bureaucrat::Fields::Field

Instance Method Details

#default_widgetObject



483
484
485
# File 'lib/bureaucrat/fields.rb', line 483

def default_widget
  Widgets::CheckboxInput
end

#to_object(value) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
# File 'lib/bureaucrat/fields.rb', line 487

def to_object(value)
  if value.kind_of?(String) && ['false', '0'].include?(value.downcase)
    value = false
  else
    value = Utils.make_bool(value)
  end

  value = super(value)

  if !value && required
    raise ValidationError.new(error_messages[:required])
  end

  value
end