Class: Packages::Nuget::SearchResultsPresenter

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize, PresenterHelpers
Defined in:
app/presenters/packages/nuget/search_results_presenter.rb

Constant Summary

Constants included from PresenterHelpers

PresenterHelpers::BLANK_STRING, PresenterHelpers::PACKAGE_DEPENDENCY, PresenterHelpers::PACKAGE_DEPENDENCY_GROUP

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Methods included from API::Helpers::RelatedResourcesHelpers

#expose_path, #expose_url, #issues_available?, #mrs_available?

Constructor Details

#initialize(search) ⇒ SearchResultsPresenter

Returns a new instance of SearchResultsPresenter.


11
12
13
14
# File 'app/presenters/packages/nuget/search_results_presenter.rb', line 11

def initialize(search)
  @search = search
  @package_versions = {}
end

Instance Method Details

#dataObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/presenters/packages/nuget/search_results_presenter.rb', line 16

def data
  strong_memoize(:data) do
    @search.results.group_by(&:name).map do |package_name, packages|
      latest_version = latest_version(packages)
      latest_package = packages.find { |pkg| pkg.version == latest_version }

      {
        type: 'Package',
        authors: '',
        name: package_name,
        version: latest_version,
        versions: build_package_versions(packages),
        summary: '',
        total_downloads: 0,
        verified: true,
        tags: tags_for(latest_package),
        metadatum: metadatum_for(latest_package)
      }
    end
  end
end