Class: Katalyst::Tables::Collection::Type::Enum

Inherits:
Value
  • Object
show all
Includes:
Helpers::Multiple
Defined in:
lib/katalyst/tables/collection/type/enum.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, #filter?, #filterable?, #to_param

Constructor Details

#initialize(multiple: true) ⇒ Enum

Returns a new instance of Enum.



10
11
12
# File 'lib/katalyst/tables/collection/type/enum.rb', line 10

def initialize(multiple: true, **)
  super
end

Instance Method Details

#suggestions(scope, attribute) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/katalyst/tables/collection/type/enum.rb', line 18

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

  raise ArgumentError, "Unknown enum #{column} for #{model}" unless model.defined_enums.has_key?(column)

  values = model.defined_enums[column].keys

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

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

#typeObject



14
15
16
# File 'lib/katalyst/tables/collection/type/enum.rb', line 14

def type
  :enum
end