Class: Esse::CLI::Index::UpdateLazyAttributes

Inherits:
BaseOperation show all
Defined in:
lib/esse/cli/index/update_lazy_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Output

colorize, formatted_runtime, print_backtrace, print_error, print_message, runtime_padding

Constructor Details

#initialize(indices:, attributes: nil, **options) ⇒ UpdateLazyAttributes

Returns a new instance of UpdateLazyAttributes.



10
11
12
13
# File 'lib/esse/cli/index/update_lazy_attributes.rb', line 10

def initialize(indices:, attributes: nil, **options)
  super(indices: indices, **options)
  @attributes = Array(attributes)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/esse/cli/index/update_lazy_attributes.rb', line 8

def attributes
  @attributes
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/esse/cli/index/update_lazy_attributes.rb', line 15

def run
  validate_options!
  indices.each do |index|
    repos = if (repo = @options[:repo])
      [index.repo(repo)]
    else
      index.repo_hash.values
    end

    repos.each do |repo|
      attrs = repo_attributes(repo)
      next unless attrs.any?

      repo.send(:each_batch_ids, **context_options) do |ids|
        attrs.each do |attribute|
          repo.update_documents_attribute(attribute, ids, bulk_options)
        end
      end
    end
  end
end