Class: Katello::ProductContentPresenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/presenters/katello/product_content_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_content, overrides) ⇒ ProductContentPresenter

Returns a new instance of ProductContentPresenter.



5
6
7
8
9
# File 'app/presenters/katello/product_content_presenter.rb', line 5

def initialize(product_content, overrides)
  @product_content = product_content
  @overrides = overrides
  super(@product_content)
end

Instance Attribute Details

#overridesObject

Returns the value of attribute overrides.



3
4
5
# File 'app/presenters/katello/product_content_presenter.rb', line 3

def overrides
  @overrides
end

#product_contentObject

Returns the value of attribute product_content.



3
4
5
# File 'app/presenters/katello/product_content_presenter.rb', line 3

def product_content
  @product_content
end

Instance Method Details

#content_overridesObject



22
23
24
25
# File 'app/presenters/katello/product_content_presenter.rb', line 22

def content_overrides
  return [] if overrides.blank?
  overrides.select { |pc| pc. == content.label }
end

#enabled_content_overrideObject



17
18
19
20
# File 'app/presenters/katello/product_content_presenter.rb', line 17

def enabled_content_override
  return nil if overrides.blank?
  overrides.find { |pc| pc. == content.label && pc.name == "enabled" }
end

#overrideObject



11
12
13
14
15
# File 'app/presenters/katello/product_content_presenter.rb', line 11

def override
  return 'default' if overrides.blank?
  override = overrides.find { |pc| pc. == content.label && pc.name == "enabled" }
  override.nil? ? 'default' : override.value
end

#statusObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/presenters/katello/product_content_presenter.rb', line 27

def status
  overidden_value = enabled_content_override&.computed_value
  if overidden_value.nil?
    {
      status: enabled ? "enabled" : "disabled",
      overridden: false
    }
  else
    {
      status: overidden_value ? "enabled" : "disabled",
      overridden: true
    }
  end
end