Sha256: 4574ec9d345026ea7e3f2829bc17b59e093e36524e80b1f95abc16aeb714f75c

Contents?: true

Size: 858 Bytes

Versions: 2

Compression:

Stored size: 858 Bytes

Contents

module ForemanOpenscap
  class OvalContent < ApplicationRecord
    audited :except => [:scap_file]
    include Authorizable
    include Taxonomix
    include ScapFileContent

    before_destroy ActiveRecord::Base::EnsureNotUsedBy.new(:oval_policies)

    scoped_search :on => :name, :complete_value => true

    has_many :oval_policies
    validates :name, :presence => true, :length => { :maximum => 255 }, uniqueness: true
    validates :url, :format => { :with => %r{\Ahttps?://} }, :allow_blank => true

    before_validation :fetch_remote_content, :if => lambda { |oval_content| oval_content.url.present? }

    def to_h
      { :id => id, :name => name, :original_filename => original_filename, :changed_at => changed_at }
    end

    private

    def fetch_remote_content
      ForemanOpenscap::Oval::SyncOvalContents.new.sync self
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_openscap-5.1.1 app/models/foreman_openscap/oval_content.rb
foreman_openscap-5.1.0 app/models/foreman_openscap/oval_content.rb