Class: Katalyst::Tables::Collection::Type::Boolean
- Inherits:
-
Value
- Object
- ActiveModel::Type::Value
- Value
- Katalyst::Tables::Collection::Type::Boolean
- Includes:
- Helpers::Delegate, Helpers::Multiple
- Defined in:
- lib/katalyst/tables/collection/type/boolean.rb
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
- #filter?(attribute, value) ⇒ Boolean
-
#initialize ⇒ Boolean
constructor
A new instance of Boolean.
- #suggestions(scope, attribute) ⇒ Object
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
#initialize ⇒ Boolean
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
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 |