Class: Cuprum::Rails::Serializers::Json::ArraySerializer
- Inherits:
-
BaseSerializer
- Object
- BaseSerializer
- Cuprum::Rails::Serializers::Json::ArraySerializer
- Defined in:
- lib/cuprum/rails/serializers/json/array_serializer.rb
Overview
Converts Array data structures to JSON based on configured serializers.
Instance Method Summary collapse
-
#call(array, context:) ⇒ Array
Converts the array to JSON using the given serializers.
Methods inherited from BaseSerializer
Instance Method Details
#call(array, context:) ⇒ Array
Converts the array to JSON using the given serializers.
First, #call finds the best serializer from the :serializers Hash for each item in the Array. This is done by walking up the object class’s ancestors to find the closest ancestor which is a key in the :serializers Hash. The corresponding value is then called with the object, and the results are combined into a new Array and returned.
26 27 28 29 30 |
# File 'lib/cuprum/rails/serializers/json/array_serializer.rb', line 26 def call(array, context:) raise ArgumentError, 'object must be an Array' unless array.is_a?(Array) array.map { |item| super(item, context: context) } end |