Class: TypedEAV::Field::MultiSelect
- Inherits:
-
Base
show all
- Defined in:
- app/models/typed_eav/field/multi_select.rb
Constant Summary
Constants inherited
from Base
Base::RESERVED_NAMES
ColumnMapping::DEFAULT_OPERATORS_BY_COLUMN, ColumnMapping::FALLBACK_OPERATORS
Instance Method Summary
collapse
Methods inherited from Base
#allowed_option_values, #clear_option_cache!, #default_value, #default_value=, #field_type_name
Instance Method Details
#allowed_values ⇒ Object
12
13
14
15
16
17
18
|
# File 'app/models/typed_eav/field/multi_select.rb', line 12
def allowed_values
if field_options.loaded?
field_options.sort_by { |o| [o.sort_order || 0, o.label.to_s] }.map(&:value)
else
field_options.sorted.pluck(:value)
end
end
|
#array_field? ⇒ Boolean
10
|
# File 'app/models/typed_eav/field/multi_select.rb', line 10
def array_field? = true
|
#cast(raw) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/models/typed_eav/field/multi_select.rb', line 20
def cast(raw)
return [nil, false] if raw.nil?
elements = Array(raw).filter_map do |v|
next nil if v.nil?
s = v.to_s
s.strip.empty? ? nil : s
end
[elements.presence, false]
end
|
#optionable? ⇒ Boolean
9
|
# File 'app/models/typed_eav/field/multi_select.rb', line 9
def optionable? = true
|
#validate_typed_value(record, val) ⇒ Object
35
36
37
38
|
# File 'app/models/typed_eav/field/multi_select.rb', line 35
def validate_typed_value(record, val)
validate_multi_option_inclusion(record, val)
validate_array_size(record, val)
end
|