autocomplete_tags_service.rb 362 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# frozen_string_literal: true

class AutocompleteTagsService
  def initialize(taggable_type)
    @taggable_type = taggable_type
  end

  # rubocop: disable CodeReuse/ActiveRecord
  def run
    @taggable_type
      .all_tags
      .pluck(:id, :name).map do |id, name|
        { id: id, title: name }
      end
  end
  # rubocop: enable CodeReuse/ActiveRecord
end