Sha256: d1a43f83004f23dab729f6bdd22f6f63f07354fb8f57ecc0f405a316d44575c4

Contents?: true

Size: 985 Bytes

Versions: 5

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

class Serega
  module SeregaPlugins
    module Batch
      module PluginsExtensions
        module ActiveRecordPreloads
          module BatchLoaderInstanceMethods
            def keys_values(*)
              data = super

              if point.has_nested_points?
                associations = point.preloads
                return data if associations.empty?

                ActiverecordPreloads::Preloader.preload(data.values.flatten(1), associations)
              end

              data
            end
          end
        end

        module Formatters
          module BatchLoaderInstanceMethods
            # Format values after they are prepared
            def keys_values(*)
              data = super

              formatter = point.attribute.formatter_resolved
              data.transform_values! { |value| formatter.call(value) } if formatter

              data
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
serega-0.6.1 lib/serega/plugins/batch/lib/plugins_extensions.rb
serega-0.6.0 lib/serega/plugins/batch/lib/plugins_extensions.rb
serega-0.5.2 lib/serega/plugins/batch/lib/plugins_extensions.rb
serega-0.5.1 lib/serega/plugins/batch/lib/plugins_extensions.rb
serega-0.5.0 lib/serega/plugins/batch/lib/plugins_extensions.rb