class OpenSCAP::Source
Attributes
raw[R]
Public Class Methods
new(param)
click to toggle source
# File lib/openscap/source.rb, line 9 def initialize(param) case param when nil raise OpenSCAPError, 'No filename specified!' when String @raw = OpenSCAP.oscap_source_new_from_file(param) when Hash @raw = create_from_memory param when FFI::Pointer @raw = param else raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with '#{param}'" end OpenSCAP.raise! if @raw.null? end
Public Instance Methods
destroy()
click to toggle source
# File lib/openscap/source.rb, line 38 def destroy OpenSCAP.oscap_source_free(@raw) @raw = nil end
save(filepath = nil)
click to toggle source
# File lib/openscap/source.rb, line 34 def save(filepath = nil) OpenSCAP.raise! unless OpenSCAP.oscap_source_save_as(@raw, filepath).zero? end
type()
click to toggle source
# File lib/openscap/source.rb, line 25 def type OpenSCAP.oscap_document_type_to_string(OpenSCAP.oscap_source_get_scap_type(@raw)) end
validate!()
click to toggle source
# File lib/openscap/source.rb, line 29 def validate! e = FFI::MemoryPointer.new(:char, 4096) OpenSCAP.raise!(e.read_string) unless OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e).zero? end
Private Instance Methods
create_from_memory(param)
click to toggle source
# File lib/openscap/source.rb, line 45 def create_from_memory(param) param[:length] = param[:content].length unless param[:length] buf = FFI::MemoryPointer.new(:char, param[:length]) buf.put_bytes(0, param[:content]) OpenSCAP.oscap_source_new_from_memory param[:content], param[:length], param[:path] end