Class: Datagrid::Filters::ExtendedBooleanFilter

Inherits:
EnumFilter show all
Defined in:
lib/datagrid/filters/extended_boolean_filter.rb

Constant Summary collapse

YES =
"YES"
NO =
"NO"
TRUTH_VALUES =
[true, "true", "y", "yes"].freeze
FALSE_VALUES =
[false, "false", "n", "no"].freeze

Instance Attribute Summary

Attributes inherited from BaseFilter

#block, #grid_class, #name, #options

Instance Method Summary collapse

Methods inherited from EnumFilter

#enum_checkboxes?, #label_options, #strict

Methods included from SelectOptions

#include_blank, #prompt, #select, #select_values

Methods inherited from BaseFilter

#allow_blank?, #allow_nil?, #apply, #default, #default_scope?, #dummy?, #enabled?, #enum_checkboxes?, #form_builder_helper_name, form_builder_helper_name, #format, #header, #input_options, #label_options, #multiple?, #parse_values, #range?, #separator, #supports_range?, #type, #unapplicable_value?

Constructor Details

#initialize(*args, **options) ⇒ ExtendedBooleanFilter

Returns a new instance of ExtendedBooleanFilter.



11
12
13
14
# File 'lib/datagrid/filters/extended_boolean_filter.rb', line 11

def initialize(*args, **options)
  options[:select] = -> { boolean_select }
  super
end

Instance Method Details

#default_input_optionsObject



21
22
23
# File 'lib/datagrid/filters/extended_boolean_filter.rb', line 21

def default_input_options
  { **super, type: "select" }
end

#execute(value, scope, grid_object) ⇒ Object



16
17
18
19
# File 'lib/datagrid/filters/extended_boolean_filter.rb', line 16

def execute(value, scope, grid_object)
  value = value.blank? ? nil : ::Datagrid::Utils.booleanize(value)
  super
end

#parse(value) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/datagrid/filters/extended_boolean_filter.rb', line 25

def parse(value)
  value = value.downcase if value.is_a?(String)
  case value
  when *TRUTH_VALUES
    YES
  when *FALSE_VALUES
    NO
  when value.blank?
    nil
  else
    super
  end
end