lib/esse/cli/templates/index.rb.erb in esse-0.0.4 vs lib/esse/cli/templates/index.rb.erb in esse-0.0.5
- old
+ new
@@ -1,25 +1,25 @@
# frozen_string_literal: true
class <%= @index_name %> < <%= @base_class %>
# plugin :active_record
# plugin :sequel
- <%- @types.each do |type| -%>
+ <%- @types.each do |type| -%>
define_type :<%= type %> do
# Collection
# ==========
#
# Collection wraps the data into an array of items that should be serialized. The first argument that is
# yielded must extends Enumerable.
# Useful for eager loading data from database or any other repository. Below is an example of a rails like
# application could load using activerecord.
#
- # collection do |conditions|
+ # collection do |conditions, &block|
# context = {}
# <%= type.camelize %>.where(conditions).find_in_batches(batch_size: 5000) do |batch|
- # yield batch, context, ...
+ # block.call batch, context, ...
# end
# end
#
#
# Serializer
@@ -39,14 +39,14 @@
# { '_id' => @<%= type %>.id, 'name' => @<%= type %>.name }
# end
# end
#
# And here you specify your serializer classe.
- # serializer <%= @index_name %>::Serializers::<%= type.camelize %>Serializer
+ # serializer Serializers::<%= type.camelize %>Serializer
#
# You can also serialize the collection entry using a block:
#
- # serializer(<%= type %>, context = {}) do
+ # serializer do |model, context = {}|
# hash = {
# name: <%= type %>.name,
# }
# # Context is just an example here. But it's useful for eager loading data.
# # I'll think a better example when implement this idea.