Class: Anchormodel::ActiveModelTypeValueMulti
- Inherits:
-
ActiveModelTypeValueSingle
- Object
- ActiveModel::Type::Value
- ActiveModelTypeValueSingle
- Anchormodel::ActiveModelTypeValueMulti
- Defined in:
- lib/anchormodel/active_model_type_value_multi.rb
Instance Attribute Summary
Attributes inherited from ActiveModelTypeValueSingle
Instance Method Summary collapse
-
#cast(values) ⇒ Object
This converts DB or input to an Anchormodel instance.
- #serializable?(values) ⇒ Boolean
-
#serialize(values) ⇒ Object
This converts an Anchormodel instance to string for DB.
Methods inherited from ActiveModelTypeValueSingle
#changed_in_place?, #initialize, #type
Constructor Details
This class inherits a constructor from Anchormodel::ActiveModelTypeValueSingle
Instance Method Details
#cast(values) ⇒ Object
This converts DB or input to an Anchormodel instance
3 4 5 |
# File 'lib/anchormodel/active_model_type_value_multi.rb', line 3 def cast(values) return values.split(',').map { |value| super(value) }.compact.to_set end |
#serializable?(values) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/anchormodel/active_model_type_value_multi.rb', line 21 def serializable?(values) return case values when Enumerable values.map { |value| super(value) }.compact.join(',') when String values.split(',').map { |value| super(value) }.compact else false end end |
#serialize(values) ⇒ Object
This converts an Anchormodel instance to string for DB
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/anchormodel/active_model_type_value_multi.rb', line 8 def serialize(values) return case values when Enumerable values.map { |value| super(value) }.compact.join(',') when String values when nil '' else fail "Attempt to set #{@attribute.attribute_name} to unsupported type #{values.class}" end end |