Sha256: ec76a52a4369da43c77ea86c55ea2c1014f3964fcde8c1be8dfd2cbc47c8aa0a

Contents?: true

Size: 1.16 KB

Versions: 57

Compression:

Stored size: 1.16 KB

Contents

module ForemanOpenscap
  module HostgroupExtensions
    extend ActiveSupport::Concern

    included do
      has_one :asset, :as => :assetable, :class_name => "::ForemanOpenscap::Asset", dependent: :destroy
      has_many :asset_policies, :through => :asset, :class_name => "::ForemanOpenscap::AssetPolicy"
      has_many :policies, :through => :asset_policies, :class_name => "::ForemanOpenscap::Policy"
    end

    def inherited_policies
      return [] unless parent

      ancestors.inject([]) do |policies, hostgroup|
        policies += hostgroup.policies
      end.uniq
    end

    def openscap_proxy
      return super if ancestry.nil? || self.openscap_proxy_id.present?
      ::SmartProxy.find_by(:id => inherited_openscap_proxy_id)
    end

    def inherited_openscap_proxy_id
      inherited_ancestry_attribute(:openscap_proxy_id)
    end

    unless defined?(Katello::System)
      private

      def inherited_ancestry_attribute(attribute)
        if ancestry.present?
          self[attribute] || self.class.sort_by_ancestry(ancestors.where("#{attribute} is not NULL")).last.try(attribute)
        else
          self.send(attribute)
        end
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
foreman_openscap-4.0.3 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-4.0.2 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-4.0.1 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-3.0.1 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-4.0.0 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-3.0.0 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-2.0.2 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.10 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-2.0.1 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.9 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-2.0.0 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.8 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.7 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.6 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.5 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.4 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.3 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.2 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.1 app/models/concerns/foreman_openscap/hostgroup_extensions.rb
foreman_openscap-1.0.0 app/models/concerns/foreman_openscap/hostgroup_extensions.rb