Class: Terraform::ModulesPresenter

Inherits:
Gitlab::View::Presenter::Simple show all
Defined in:
app/presenters/terraform/modules_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::View::Presenter::Base

#__subject__, #can?, #declarative_policy_delegate, #is_a?, #present, #url_builder, #web_path, #web_url

Methods included from Gitlab::Allowable

#can?

Methods included from Gitlab::Routing

add_helpers, includes_helpers, redirect_legacy_paths, url_helpers

Constructor Details

#initialize(packages, system) ⇒ ModulesPresenter

Returns a new instance of ModulesPresenter.


9
10
11
12
# File 'app/presenters/terraform/modules_presenter.rb', line 9

def initialize(packages, system)
  @packages = packages
  @system = system
end

Instance Attribute Details

#packagesObject

Returns the value of attribute packages.


5
6
7
# File 'app/presenters/terraform/modules_presenter.rb', line 5

def packages
  @packages
end

#systemObject

Returns the value of attribute system.


5
6
7
# File 'app/presenters/terraform/modules_presenter.rb', line 5

def system
  @system
end

Instance Method Details

#modulesObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/presenters/terraform/modules_presenter.rb', line 14

def modules
  project_url = @packages.first&.project&.web_url
  versions = @packages.map do |package|
    {
      'version' => package.version,
      'submodules' => [],
      'root' => {
        'dependencies' => [],
        'providers' => [
          {
            'name' => @system,
            'version' => ''
          }
        ]
      }
    }
  end

  [
    {
      'versions' => versions,
      'source' => project_url
    }.compact
  ]
end