Class: Libvirt::Xml::Generic
- Inherits:
-
Object
- Object
- Libvirt::Xml::Generic
show all
- Defined in:
- lib/libvirt/xml/generic.rb
Direct Known Subclasses
Disk, Domain, Graphics, Interface, IpAddress, MaxVcpu, Memory, Network, StoragePool, StorageVolume, Vcpu
Constant Summary
collapse
- TRUE_VALUES =
%w[yes on].freeze
- FALSE_VALUES =
%w[no off].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(xml_node) ⇒ Generic
Returns a new instance of Generic.
52
53
54
55
|
# File 'lib/libvirt/xml/generic.rb', line 52
def initialize(xml_node)
@xml_node = xml_node
parse_xml_node
end
|
Class Method Details
.attribute(name, **options) ⇒ Object
29
30
31
32
|
# File 'lib/libvirt/xml/generic.rb', line 29
def self.attribute(name, **options)
_attributes_opts.merge!(name.to_sym => options.dup)
attr_accessor name
end
|
.attributes(*names) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/libvirt/xml/generic.rb', line 21
def self.attributes(*names)
options = names.
names.each do |name|
_attributes_opts.merge!(name.to_sym => options.dup)
end
attr_accessor(*names)
end
|
.build(**attrs) ⇒ Xml::Base
Build xml object with attributes.
44
45
46
47
48
49
|
# File 'lib/libvirt/xml/generic.rb', line 44
def self.build(**attrs)
xml_node = Nokogiri::XML(nil)
obj = new(xml_node)
attrs.each { |key, val| obj.public_send("#{key}=", val) }
obj
end
|
.inherited(subclass) ⇒ Object
12
13
14
15
|
# File 'lib/libvirt/xml/generic.rb', line 12
def self.inherited(subclass)
subclass._root_path = '.'
subclass._attributes_opts = _attributes_opts.dup
end
|
.load(xml) ⇒ Class<LibvirtXml::Generic>
36
37
38
39
|
# File 'lib/libvirt/xml/generic.rb', line 36
def self.load(xml)
xml_node = Nokogiri::XML(xml).xpath(_root_path).first
new(xml_node)
end
|
.root_path(path) ⇒ Object
17
18
19
|
# File 'lib/libvirt/xml/generic.rb', line 17
def self.root_path(path)
self._root_path = path
end
|
Instance Method Details
#[](attr) ⇒ Object?
59
60
61
|
# File 'lib/libvirt/xml/generic.rb', line 59
def [](attr)
read_attribute(attr)
end
|
#[]=(attr, value) ⇒ Object?
66
67
68
|
# File 'lib/libvirt/xml/generic.rb', line 66
def []=(attr, value)
write_attribute(attr, value)
end
|
#to_h ⇒ Hash{Symbol=>(Object,nil)}
71
72
73
74
75
76
|
# File 'lib/libvirt/xml/generic.rb', line 71
def to_h
_attributes_opts.map do |name, _opts|
value = public_send(name)
[name, serialize_for_hash(value)]
end.to_h
end
|
#to_xml ⇒ String
79
80
81
|
# File 'lib/libvirt/xml/generic.rb', line 79
def to_xml
@xml_node.to_xml
end
|