Class: Esse::CLI::Index

Inherits:
Base
  • Object
show all
Defined in:
lib/esse/cli/index.rb

Defined Under Namespace

Classes: BaseOperation, Close, Create, Delete, Import, Open, Reset, UpdateAliases, UpdateMapping, UpdateSettings

Instance Method Summary collapse

Instance Method Details

#close(*index_classes) ⇒ Object



86
87
88
89
# File 'lib/esse/cli/index.rb', line 86

def close(*index_classes)
  require_relative 'index/close'
  Close.new(indices: index_classes, **options.to_h.transform_keys(&:to_sym)).run
end

#create(*index_classes) ⇒ Object



43
44
45
46
47
# File 'lib/esse/cli/index.rb', line 43

def create(*index_classes)
  require_relative 'index/create'
  opts = HashUtils.deep_transform_keys(options.to_h, &:to_sym)
  Create.new(indices: index_classes, **opts).run
end

#delete(*index_classes) ⇒ Object



51
52
53
54
# File 'lib/esse/cli/index.rb', line 51

def delete(*index_classes)
  require_relative 'index/delete'
  Delete.new(indices: index_classes, **options.to_h.transform_keys(&:to_sym)).run
end

#import(*index_classes) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/esse/cli/index.rb', line 105

def import(*index_classes)
  require_relative 'index/import'
  opts = HashUtils.deep_transform_keys(options.to_h, &:to_sym)
  %i[preload_lazy_attributes eager_load_lazy_attributes update_lazy_attributes].each do |key|
    if (val = opts.delete(key)) && val != 'false'
      opts[key] = (val == 'true') ? true : val.split(',')
    end
  end
  Import.new(indices: index_classes, **opts).run
end

#open(*index_classes) ⇒ Object



93
94
95
96
# File 'lib/esse/cli/index.rb', line 93

def open(*index_classes)
  require_relative 'index/open'
  Open.new(indices: index_classes, **options.to_h.transform_keys(&:to_sym)).run
end

#reset(*index_classes) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/esse/cli/index.rb', line 22

def reset(*index_classes)
  require_relative 'index/reset'
  opts = HashUtils.deep_transform_keys(options.to_h, &:to_sym)
  opts[:reindex] = Parser::BoolOrHash.new(:reindex, default: false).parse(opts[:reindex])
  opts[:import] = Parser::BoolOrHash.new(:import, default: true).parse(opts[:import])
  if opts[:import] && opts[:reindex]
    raise ArgumentError, 'You cannot use --import and --reindex together'
  end
  Reset.new(indices: index_classes, **opts).run
end

#update_aliases(*index_classes) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/esse/cli/index.rb', line 58

def update_aliases(*index_classes)
  require_relative 'index/update_aliases'

  kwargs = options.to_h.transform_keys(&:to_sym)
  kwargs[:suffix] = (kwargs[:suffix] || []).flat_map { |s| s.split(',') }.uniq
  UpdateAliases.new(indices: index_classes, **kwargs).run
end

#update_mapping(*index_classes) ⇒ Object



79
80
81
82
# File 'lib/esse/cli/index.rb', line 79

def update_mapping(*index_classes)
  require_relative 'index/update_mapping'
  UpdateMapping.new(indices: index_classes, **options.to_h.transform_keys(&:to_sym)).run
end

#update_settings(*index_classes) ⇒ Object



70
71
72
73
74
# File 'lib/esse/cli/index.rb', line 70

def update_settings(*index_classes)
  require_relative 'index/update_settings'
  opts = HashUtils.deep_transform_keys(options.to_h, &:to_sym)
  UpdateSettings.new(indices: index_classes, **opts).run
end