Sha256: 4658073228bba9adcc82dd49d525c9534f9d4cacac13981290743c8d81f0eb1e

Contents?: true

Size: 979 Bytes

Versions: 3

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

class <%= @index_name %> < <%= @base_class %>
  module Collections
    class <%= @type.camelize %>Collection
      include Enumerable

      # @param params [Hash] List of parameters
      def initialize(**params)
        @params = params
      end

      # Find all <%= @type %> in batches
      #
      # @yield [Array<<%= @type.camelize %>>]
      # @see <%= @index_name %>::<%= @type.camelize %>#collection
      def each
        offset = 0
        while (rows = find_all(offset))
          break if rows.none?

          # You may preload associations before serialize them
          # associations = preload_associations!(rows)
          # yield(row, associations)
          offset += 1

          yield(rows, **params)
        end
      end

      protected

      attr_reader :params

      # @param offset [Number] Offset to start from
      def find_all(offset)
        # @TODO load data from persistent store
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
esse-0.2.0 lib/esse/cli/templates/type_collection.rb.erb
esse-0.1.3 lib/esse/cli/templates/type_collection.rb.erb
esse-0.1.2 lib/esse/cli/templates/type_collection.rb.erb