lib/esse/cli/templates/index.rb.erb in esse-0.2.2 vs lib/esse/cli/templates/index.rb.erb in esse-0.2.3

- old
+ new

@@ -1,68 +1,73 @@ # frozen_string_literal: true -<%- @types.each do |type| -%> +<%- @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] -%> -<%- @types.each do |type| -%> -require_relative '<%= @index_name.demodulize.underscore.to_s %>/serializers/<%= type.underscore %>_serializer' -<%- end if @cli_options[:serializers] -%> +<%- @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 @types.empty? -%> - <%- 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) + <%- 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 -%> - <%- if @cli_options[:serializers] -%> - serializer Serializers::Serializer - <%- else -%> - serializer do |object, **_context| - { - id: object.id, - name: object.name, - } - end - <%- end # if @cli_options[:serializers] -%> - <%- end # /@types.empty?-%> + <%- end # /@repos.empty?-%> + <%- @repos.each do |type| -%> - <%- @types.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) + block.call(batch, **context) end end <%- end -%> - <%- if @cli_options[:serializers] -%> - serializer Serializers::<%= type.camelize %>Serializer + <%- if @cli_options[:documents] -%> + document Documents::<%= type.camelize %>Document <%- else -%> - serializer do |<%= type.underscore %>, **_context| + document do |<%= type.underscore %>, **_context| { id: <%= type.underscore %>.id, name: <%= @index_name.underscore %>.name, } end <%- end -%> end - - <%- end #@types.each do |type| -%> + <%- end #@repos.each do |type| -%> end