Class: Typelizer::SerializerPlugins::OjSerializers

Inherits:
Base
  • Object
show all
Defined in:
lib/typelizer/serializer_plugins/oj_serializers.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #meta_fields, #root_key

Constructor Details

This class inherits a constructor from Typelizer::SerializerPlugins::Base

Instance Method Details

#propertiesObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/typelizer/serializer_plugins/oj_serializers.rb', line 6

def properties
  transform_keys = serializer.try(:_transform_keys)
  attributes = serializer._attributes
  attributes = attributes.transform_keys(&transform_keys) if transform_keys

  attributes
    .flat_map do |key, options|
      if options[:association] == :flat
        context.interface_for(options.fetch(:serializer)).properties
      else
        type = options[:serializer] ? context.interface_for(options[:serializer]) : options[:type]
        Property.new(
          name: key,
          type: type,
          optional: options[:optional] || options.key?(:if),
          nullable: options[:nullable],
          multi: options[:association] == :many,
          column_name: options.fetch(:value_from)
        )
      end
    end
end