Class: OpenSCAP::Source
- Inherits:
-
Object
- Object
- OpenSCAP::Source
- Defined in:
- lib/openscap/source.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(param) ⇒ Source
constructor
A new instance of Source.
- #save(filepath = nil) ⇒ Object
- #type ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(param) ⇒ Source
Returns a new instance of Source.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/openscap/source.rb', line 18 def initialize(param) case param when nil fail 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 fail OpenSCAP::OpenSCAPError, "Cannot initialize OpenSCAP::Source with '#{param}'" end OpenSCAP.raise! if @raw.null? end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
16 17 18 |
# File 'lib/openscap/source.rb', line 16 def raw @raw end |
Instance Method Details
#destroy ⇒ Object
49 50 51 52 |
# File 'lib/openscap/source.rb', line 49 def destroy OpenSCAP.oscap_source_free(@raw) @raw = nil end |
#save(filepath = nil) ⇒ Object
45 46 47 |
# File 'lib/openscap/source.rb', line 45 def save(filepath = nil) OpenSCAP.raise! unless OpenSCAP.oscap_source_save_as(@raw, filepath) == 0 end |
#type ⇒ Object
34 35 36 |
# File 'lib/openscap/source.rb', line 34 def type OpenSCAP.oscap_document_type_to_string(OpenSCAP.oscap_source_get_scap_type(@raw)) end |
#validate! ⇒ Object
38 39 40 41 42 43 |
# File 'lib/openscap/source.rb', line 38 def validate! e = FFI::MemoryPointer.new(:char, 4096) if 0 != OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e) OpenSCAP.raise! e.read_string end end |