Class: ACIrb::Loader
- Inherits:
-
Object
- Object
- ACIrb::Loader
- Defined in:
- lib/loader.rb
Class Method Summary collapse
- .get_mo_from_hash(parent_mo, hash) ⇒ Object
- .get_mo_from_xml(parent_mo, element) ⇒ Object
- .load_hash(hash) ⇒ Object
- .load_json(doc) ⇒ Object
- .load_json_str(json_data) ⇒ Object
- .load_xml(doc) ⇒ Object
- .load_xml_str(xml_str) ⇒ Object
Class Method Details
.get_mo_from_hash(parent_mo, hash) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/loader.rb', line 62 def self.get_mo_from_hash(parent_mo, hash) class_name = hash.keys[0] values = hash[class_name] unless ACIrb::CLASSMAP.include?(class_name) fail 'Could not find class "%s" defined in "%s"' % [class_name, hash] end mo = ACIrb.const_get(ACIrb::CLASSMAP[class_name]) create_attr = {} (values['attributes'] || {}).each do |propName, propVal| create_attr[propName.to_s] = propVal end create_attr[:mark_dirty] = false mo = mo.new(parent_mo, create_attr) (values['children'] || []).each do |child| mo.add_child(get_mo_from_hash(mo, child)) end mo end |
.get_mo_from_xml(parent_mo, element) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/loader.rb', line 19 def self.get_mo_from_xml(parent_mo, element) class_name = element.name unless ACIrb::CLASSMAP.include?(class_name) fail 'Could not find class "%s" defined in "%s"' % \ [class_name, element.to_s] end mo = ACIrb.const_get(ACIrb::CLASSMAP[class_name]) create_attr = {} element.attributes.each do |k, v| create_attr[k.to_s] = v.to_s end create_attr[:mark_dirty] = false mo = mo.new(parent_mo, create_attr) element.elements.each do |e| mo.add_child(get_mo_from_xml(mo, e)) end mo end |
.load_hash(hash) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/loader.rb', line 51 def self.load_hash(hash) top = hash.keys[0] attrib = hash[top]['attributes'] || {} dn_str = attrib['dn'] parent_mo = ACIrb::Naming.get_mo_from_dn(dn_str).parent \ unless dn_str.nil? get_mo_from_hash(parent_mo, hash) end |
.load_json(doc) ⇒ Object
47 48 49 |
# File 'lib/loader.rb', line 47 def self.load_json(doc) load_hash(doc) end |
.load_json_str(json_data) ⇒ Object
42 43 44 45 |
# File 'lib/loader.rb', line 42 def self.load_json_str(json_data) doc = JSON.parse(json_data, symbolize_names: false) load_json(doc) end |
.load_xml(doc) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/loader.rb', line 11 def self.load_xml(doc) dn_str = doc.attributes['dn'].to_s parent_mo = ACIrb::Naming.get_mo_from_dn(dn_str).parent if dn_str get_mo_from_xml(parent_mo, doc) end |
.load_xml_str(xml_str) ⇒ Object
6 7 8 9 |
# File 'lib/loader.rb', line 6 def self.load_xml_str(xml_str) doc = Nokogiri::XML(xml_str) load_xml(doc.root) end |