Class: Acta::Types::Array
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Acta::Types::Array
- Defined in:
- lib/acta/types/array.rb
Overview
Wraps any other Acta type as a list-of-element type. Used internally by ‘attribute :foo, array_of: Class` (or `array_of: :symbol`); not constructed directly by consumers.
Instance Method Summary collapse
- #cast(value) ⇒ Object
- #deserialize(value) ⇒ Object
-
#initialize(element_type) ⇒ Array
constructor
A new instance of Array.
- #serialize(value) ⇒ Object
Constructor Details
#initialize(element_type) ⇒ Array
Returns a new instance of Array.
11 12 13 14 |
# File 'lib/acta/types/array.rb', line 11 def initialize(element_type) super() @element_type = element_type end |
Instance Method Details
#cast(value) ⇒ Object
16 17 18 19 20 |
# File 'lib/acta/types/array.rb', line 16 def cast(value) return nil if value.nil? Kernel.Array(value).map { |el| @element_type.cast(el) } end |
#deserialize(value) ⇒ Object
28 29 30 31 32 |
# File 'lib/acta/types/array.rb', line 28 def deserialize(value) return nil if value.nil? value.map { |el| @element_type.deserialize(el) } end |
#serialize(value) ⇒ Object
22 23 24 25 26 |
# File 'lib/acta/types/array.rb', line 22 def serialize(value) return nil if value.nil? value.map { |el| @element_type.serialize(el) } end |