Method: ACIrb::Loader.get_mo_from_hash

Defined in:
lib/loader.rb

.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