# frozen_string_literal: true <%- @repos.each do |type| -%> require_relative '<%= @index_name.demodulize.underscore.to_s %>/collections/<%= type.underscore %>_collection' <%- end if @cli_options[:collections] && !@cli_options[:active_record] -%> <%- @repos.each do |type| -%> require_relative '<%= @index_name.demodulize.underscore.to_s %>/documents/<%= type.underscore %>_document' <%- end if @cli_options[:documents] -%> class <%= @index_name %> < <%= @base_class %> <%-if @index_cluster_id -%> self.cluster_id = :<%= @index_cluster_id %> <%- end -%> <%- if @cli_options[:active_record] -%> plugin :active_record <%- end -%> <%- if @repos.empty? -%> repository :default do <%- if @cli_options[:active_record] -%> collection ::<%= @index_name.camelize %>.all <%- elsif @cli_options[:collections] -%> collection Collections::Collection <%- else -%> collection do |**context, &block| query = <%= @index_name.camelize.sub(/Index$/, '') %>.all query = query.where(id: context[:id]) if context[:id] query.find_in_batches(batch_size: 1_000) do |batch| block.call(batch, **context) end end <%- end -%> <%- if @cli_options[:documents] -%> document Documents::Document <%- else -%> document do |object, **_context| { id: object.id, name: object.name, } end <%- end # if @cli_options[:documents] -%> end <%- end # /@repos.empty?-%> <%- @repos.each do |type| -%> repository :<%= type.underscore %> do <%- if @cli_options[:active_record] -%> collection ::<%= type.camelize %>.all <%- elsif @cli_options[:collections] -%> collection Collections::<%= type.camelize %>Collection <%- else -%> collection do |**context, &block| query = <%= type.camelize %>.all query = query.where(id: context[:id]) if context[:id] query.find_in_batches(batch_size: 1_000) do |batch| block.call(batch, **context) end end <%- end -%> <%- if @cli_options[:documents] -%> document Documents::<%= type.camelize %>Document <%- else -%> document do |<%= type.underscore %>, **_context| { id: <%= type.underscore %>.id, name: <%= @index_name.underscore %>.name, } end <%- end -%> end <%- end #@repos.each do |type| -%> end