Class: Katalyst::Tables::Collection::Type::Enum
- Inherits:
-
Value
- Object
- ActiveModel::Type::Value
- Value
- Katalyst::Tables::Collection::Type::Enum
- Includes:
- Helpers::Multiple
- Defined in:
- lib/katalyst/tables/collection/type/enum.rb
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
-
#initialize(multiple: true) ⇒ Enum
constructor
A new instance of Enum.
- #suggestions(scope, attribute) ⇒ Object
- #type ⇒ Object
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
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 |
#type ⇒ Object
14 15 16 |
# File 'lib/katalyst/tables/collection/type/enum.rb', line 14 def type :enum end |