Sha256: 5f6ba5fb441f4eb665359080deea6aee643188228a809988019691a191b52231

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

module Katello
  class ProductContentPresenter < SimpleDelegator
    attr_accessor :product_content, :overrides

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

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

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

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

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katello-4.15.0 app/presenters/katello/product_content_presenter.rb
katello-4.15.0.rc2 app/presenters/katello/product_content_presenter.rb
katello-4.15.0.rc1 app/presenters/katello/product_content_presenter.rb