Class: Katalyst::Tables::Collection::Type::Boolean

Inherits:
Value
  • Object
show all
Includes:
Helpers::Delegate, Helpers::Multiple
Defined in:
lib/katalyst/tables/collection/type/boolean.rb

Instance Attribute Summary

Attributes inherited from Value

#scope

Instance Method Summary collapse

Methods included from Helpers::Multiple

#cast, #default_value, #deserialize, #multiple?, #serialize, #to_param, #value_for_multiple

Methods inherited from Value

#filter, #filterable?, #to_param

Constructor Details

#initializeBoolean

Returns a new instance of Boolean.



11
12
13
# File 'lib/katalyst/tables/collection/type/boolean.rb', line 11

def initialize(**)
  super(**, delegate: ActiveModel::Type::Boolean)
end

Instance Method Details

#filter?(attribute, value) ⇒ Boolean

Returns:



15
16
17
18
19
20
21
22
23
# File 'lib/katalyst/tables/collection/type/boolean.rb', line 15

def filter?(attribute, value)
  return false unless filterable?

  if attribute.came_from_user?
    attribute.value_before_type_cast.present? || value === false
  else
    !value.nil? && !value.eql?([])
  end
end

#suggestions(scope, attribute) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/katalyst/tables/collection/type/boolean.rb', line 25

def suggestions(scope, attribute)
  _, model, column = model_and_column_for(scope, attribute)

  values = %w[true false]

  if attribute.value_before_type_cast.present?
    values = values.select { |value| value.include?(attribute.value_before_type_cast) }
  end

  values.map { |v| constant_suggestion(attribute:, model:, column:, value: deserialize(v)) }
end