Class: OpenSCAP::Source
- Inherits:
-
Object
- Object
- OpenSCAP::Source
- Defined in:
- lib/openscap/source.rb
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(param) ⇒ Source
constructor
A new instance of Source.
- #raw ⇒ Object
- #save(filepath = nil) ⇒ Object
- #type ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(param) ⇒ Source
Returns a new instance of Source.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/openscap/source.rb', line 14 def initialize(param) case param when nil raise OpenSCAPError, "No filename specified!" when String @s = OpenSCAP.oscap_source_new_from_file(param) when Hash @s = OpenSCAP.oscap_source_new_from_memory param[:content], param[:content].length, param[:path] when FFI::Pointer @s = param else raise OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Source with '#{param}'" end OpenSCAP.raise! if @s.null? end |
Instance Method Details
#destroy ⇒ Object
50 51 52 53 |
# File 'lib/openscap/source.rb', line 50 def destroy OpenSCAP.oscap_source_free(@s) @s = nil end |
#raw ⇒ Object
42 43 44 |
# File 'lib/openscap/source.rb', line 42 def raw @s end |
#save(filepath = nil) ⇒ Object
46 47 48 |
# File 'lib/openscap/source.rb', line 46 def save(filepath=nil) OpenSCAP.raise! unless OpenSCAP.oscap_source_save_as(raw, filepath) == 0 end |
#type ⇒ Object
30 31 32 |
# File 'lib/openscap/source.rb', line 30 def type OpenSCAP.oscap_document_type_to_string(OpenSCAP.oscap_source_get_scap_type(@s)) end |
#validate! ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/openscap/source.rb', line 34 def validate! e = FFI::MemoryPointer.new(:char, 4096) if 0 != OpenSCAP.oscap_source_validate(@s, XmlReporterCallback, e) OpenSCAP.raise! e.read_string end end |