Class: Avo::Fields::BooleanField
- Defined in:
- lib/avo/app/fields/boolean_field.rb
Instance Attribute Summary
Attributes inherited from Field
#block, #component, #computable, #default, #format_using, #help, #id, #is_array_param, #is_object_param, #name, #null_values, #nullable, #placeholder, #readonly, #required, #sortable, #updatable
Attributes included from FieldExtensions::VisibleOnDifferentViews
#show_on_create, #show_on_edit, #show_on_index, #show_on_show
Instance Method Summary collapse
- #falsy_values ⇒ Object
- #hydrate_field(fields, model, resource, view) ⇒ Object
-
#initialize(name, **args, &block) ⇒ BooleanField
constructor
A new instance of BooleanField.
- #resolve_attribute(value) ⇒ Object
- #truthy_values ⇒ Object
Methods inherited from Field
#database_id, #fetch_for_action, #fetch_for_resource, #fill_field, #has_own_panel?
Methods included from FieldExtensions::HasFieldName
#field_name, #field_name_attribute, #get_field_name
Methods included from FieldExtensions::VisibleOnDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(name, **args, &block) ⇒ BooleanField
Returns a new instance of BooleanField.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/avo/app/fields/boolean_field.rb', line 4 def initialize(name, **args, &block) @defaults = { sortable: true, component: 'boolean-field', computable: true, } super(name, **args, &block) @true_value = args[:true_value].present? ? args[:true_value] : true @false_value = args[:false_value].present? ? args[:false_value] : false end |
Instance Method Details
#falsy_values ⇒ Object
33 34 35 |
# File 'lib/avo/app/fields/boolean_field.rb', line 33 def falsy_values ['false', @false_value] end |
#hydrate_field(fields, model, resource, view) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/avo/app/fields/boolean_field.rb', line 17 def hydrate_field(fields, model, resource, view) { value: resolve_attribute(fields[:value]), true_value: @true_value, false_value: @false_value, } end |
#resolve_attribute(value) ⇒ Object
25 26 27 |
# File 'lib/avo/app/fields/boolean_field.rb', line 25 def resolve_attribute(value) value.present? ? value.in?(truthy_values) : value end |
#truthy_values ⇒ Object
29 30 31 |
# File 'lib/avo/app/fields/boolean_field.rb', line 29 def truthy_values ['true', @true_value] end |