Skip to content

Commit

Permalink
add lazy-update-document-attributes and eager-include-document-attrib…
Browse files Browse the repository at this point in the history
…utes to import cli command
  • Loading branch information
marcosgz committed Jul 9, 2024
1 parent b98f799 commit 2b7ef4e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/esse/cli/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,20 @@ def open(*index_classes)
option :suffix, type: :string, default: nil, aliases: '-s', desc: 'Suffix to append to index name'
option :context, type: :hash, default: {}, required: true, desc: 'List of options to pass to the index class'
option :repo, type: :string, default: nil, alias: '-r', desc: 'Repository to use for import'
option :eager_include_document_attributes, type: :string, default: nil, desc: 'Comma separated list of lazy document attributes to include to the bulk index request'
option :lazy_update_document_attributes, type: :string, default: nil, desc: 'Comma separated list of lazy document attributes to bulk update after the bulk index request'
def import(*index_classes)
require_relative 'index/import'
Import.new(indices: index_classes, **HashUtils.deep_transform_keys(options.to_h, &:to_sym)).run
opts = HashUtils.deep_transform_keys(options.to_h, &:to_sym)
opts.delete(:lazy_update_document_attributes) if opts[:lazy_update_document_attributes] == 'false'
opts.delete(:eager_include_document_attributes) if opts[:eager_include_document_attributes] == 'false'
if (val = opts[:eager_include_document_attributes])
opts[:eager_include_document_attributes] = (val == 'true') ? true : val.split(',')
end
if (val = opts[:lazy_update_document_attributes])
opts[:lazy_update_document_attributes] = (val == 'true') ? true : val.split(',')
end
Import.new(indices: index_classes, **opts).run
end
end
end
Expand Down
40 changes: 40 additions & 0 deletions spec/esse/cli/index/import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,46 @@
expect(CitiesIndex).to receive(:import).and_return(true)
cli_exec(%w[index import CountiesIndex CitiesIndex])
end

it 'allows --eager-include-document-attributes as a comma separated list' do
expect(CountiesIndex).to receive(:import).with(eager_include_document_attributes: %w[foo bar], context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --eager-include-document-attributes=foo,bar])
end

it 'allows --lazy-update-document-attributes as a single value' do
expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: %w[foo], context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=foo])
end

it 'allows --lazy-update-document-attributes as true' do
expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: true, context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=true])
end

it 'allows --lazy-update-document-attributes as false' do
expect(CountiesIndex).to receive(:import).with(context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=false])
end

it 'allows --lazy-update-document-attributes as a comma separated list' do
expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: %w[foo bar], context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=foo,bar])
end

it 'allows --lazy-update-document-attributes as a single value' do
expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: %w[foo], context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=foo])
end

it 'allows --lazy-update-document-attributes as true' do
expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: true, context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=true])
end

it 'allows --lazy-update-document-attributes as false' do
expect(CountiesIndex).to receive(:import).with(context: {}).and_return(true)
cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=false])
end
end
end
end

0 comments on commit 2b7ef4e

Please sign in to comment.