Sha256: dc9a55027d527dc5dd529a44130ba24187dd151f667990929635f98e4628b50f

Contents?: true

Size: 936 Bytes

Versions: 23

Compression:

Stored size: 936 Bytes

Contents

require "sup/index"

module Redwood
  # Provides label tweaking service to the user.
  # Working as the backend of ConsoleMode.
  #
  # Should become the backend of bin/sup-tweak-labels in the future.
  class LabelService
    # @param index [Redwood::Index]
    def initialize index=Index.instance
      @index = index
    end

    def add_labels query, *labels
      run_on_each_message(query) do |m|
        labels.each {|l| m.add_label l }
      end
    end

    def remove_labels query, *labels
      run_on_each_message(query) do |m|
        labels.each {|l| m.remove_label l }
      end
    end


    private
    def run_on_each_message query, &operation
      count = 0

      find_messages(query).each do |m|
        operation.call(m)
        @index.update_message_state m
        count += 1
      end

      @index.save_index
      count
    end

    def find_messages query
      @index.find_messages(query)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
sup-1.2 lib/sup/service/label_service.rb
sup-1.1 lib/sup/service/label_service.rb
sup-1.0 lib/sup/service/label_service.rb
sup-0.23 lib/sup/service/label_service.rb
sup-0.22.1 lib/sup/service/label_service.rb
sup-0.22.0 lib/sup/service/label_service.rb
sup-0.21.0 lib/sup/service/label_service.rb
sup-0.20.0 lib/sup/service/label_service.rb
sup-0.19.0 lib/sup/service/label_service.rb
sup-0.18.0 lib/sup/service/label_service.rb
sup-0.17.0 lib/sup/service/label_service.rb
sup-0.16.0 lib/sup/service/label_service.rb
sup-0.15.4 lib/sup/service/label_service.rb
sup-0.15.3 lib/sup/service/label_service.rb
sup-0.15.2 lib/sup/service/label_service.rb
sup-0.15.1 lib/sup/service/label_service.rb
sup-0.15.0 lib/sup/service/label_service.rb
sup-0.14.1.1 lib/sup/service/label_service.rb
sup-0.13.2.1 lib/sup/service/label_service.rb
sup-0.14.1 lib/sup/service/label_service.rb