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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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? begin yield self ensure destroy end if block_given? end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
7 8 9 |
# File 'lib/openscap/source.rb', line 7 def raw @raw end |
Instance Method Details
#destroy ⇒ Object
44 45 46 47 |
# File 'lib/openscap/source.rb', line 44 def destroy OpenSCAP.oscap_source_free(@raw) @raw = nil end |
#save(filepath = nil) ⇒ Object
40 41 42 |
# File 'lib/openscap/source.rb', line 40 def save(filepath = nil) OpenSCAP.raise! unless OpenSCAP.oscap_source_save_as(@raw, filepath).zero? end |
#type ⇒ Object
31 32 33 |
# File 'lib/openscap/source.rb', line 31 def type OpenSCAP.oscap_document_type_to_string(OpenSCAP.oscap_source_get_scap_type(@raw)) end |
#validate! ⇒ Object
35 36 37 38 |
# File 'lib/openscap/source.rb', line 35 def validate! e = FFI::MemoryPointer.new(:char, 4096) OpenSCAP.raise!(e.read_string) unless OpenSCAP.oscap_source_validate(@raw, XmlReporterCallback, e).zero? end |